V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
q770787217
V2EX  ›  JavaScript

JS 代码如何合并? 都是跳转代码 功能不同

  •  
  •   q770787217 · 2018-09-28 13:09:26 +08:00 · 3266 次点击
    这是一个创建于 2029 天前的主题,其中的信息可能已经有所发展或是发生改变。
    JS 代码如何合并? 都是跳转代码 功能不同
    根据来路跳转和根据设备跳转的
    首先根据来路判断跳转 移动设备的跳转到 http://a.com/m PC 设备的跳转到 http://a.com/PC
    如何合并 代码如下:
    来路跳转
    <script>
    var regexp=/\.(sogou|soso|baidu|google|youdao|yahoo|bing|118114|biso|gougou|ifeng|ivc|sooule|niuhu|biso)(\.[a-z0-9\-]+){1,2}\//ig;
    var where =document.referrer;
    if(regexp.test(where))
    {
    window.location.href='http://www.badcatu.com'
    }
    </script>

    设备跳转
    <script>
    var is_mobi = navigator.userAgent.toLowerCase().match(/(ipod|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null;
    if (is_mobi) {
    window.location.href = "http://a.com/m";
    }
    else {
    window.location.href = "http://a.com/pc";
    }
    </script>
    10 条回复    2018-09-28 18:30:51 +08:00
    Pastsong
        1
    Pastsong  
       2018-09-28 13:30:20 +08:00
    这才几行有什么好合并的
    q770787217
        2
    q770787217  
    OP
       2018-09-28 15:35:00 +08:00
    @Pastsong 两个 JS 功能合并到一个 JS 里
    lqh9428
        3
    lqh9428  
       2018-09-28 16:00:50 +08:00
    没人打开他想跳转的那个地方吗?
    q770787217
        4
    q770787217  
    OP
       2018-09-28 17:03:26 +08:00
    @lqh9428 我有一个流量中转页面需要这个功能
    q770787217
        5
    q770787217  
    OP
       2018-09-28 17:04:18 +08:00
    @q770787217 我现在要跳转两次 有点费时间
    locoz
        6
    locoz  
       2018-09-28 17:20:30 +08:00
    @lqh9428 #3 hhhhh
    xxx749
        7
    xxx749  
       2018-09-28 17:55:07 +08:00 via Android
    来源判定前套客户端判定?
    q770787217
        8
    q770787217  
    OP
       2018-09-28 18:00:15 +08:00
    @xxx749 来源判断 是否符合跳转规则 符合 移动设备的跳转到 A 网址 相反 跳转到 B 网址
    xxx749
        9
    xxx749  
       2018-09-28 18:15:46 +08:00 via Android
    if(regexp.test(where))
    {
    window.location.href = is_mobi ? {移动网址} : {pc 网址}
    }
    q770787217
        10
    q770787217  
    OP
       2018-09-28 18:30:51 +08:00
    @xxx749 来源判断 是否符合跳转规则 这个怎么写?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1366 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 17:31 · PVG 01:31 · LAX 10:31 · JFK 13:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.