【问题标题】:how to redirect mobile website to normal version如何将移动网站重定向到正常版本
【发布时间】:2013-10-14 16:27:58
【问题描述】:

我实际上做了一个带有移动版本的网站(在另一个带有第二个 index.html 的文件夹中)

我已使用此脚本将移动设备从桌面版重定向到移动版

if ( navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i) ){
    window.location.href = "http://m.website.net" + document.location.hash;
}    

这很好,但问题是共享移动版本的人会将人们发送到移动设备,因为移动网址。所以我尝试像这样将它们自动重定向到桌面版本

if (! navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i) ){
    window.location.href = "http://www.website.net" + document.location.hash;
}

这在 iphone 上工作但用 ipad 创建了一个无限循环,请问我该怎么做? 我只能使用 javascript 来做到这一点

我不能像这样使用脚本 if (screen.width <= 960) {document.location = mobile.html";} 因为 ipad 视网膜等分辨率

【问题讨论】:

    标签: javascript ipad mobile detection


    【解决方案1】:

    这也会导致 iPod 无限循环。您的第二个脚本中应该缺少 !。

    if (!navigator.userAgent.match(/iPhone/i) && !navigator.userAgent.match(/iPod/i) && !navigator.userAgent.match(/iPad/i) ){
        window.location.href = "http://www.website.net" + document.location.hash;
    }
    

    您还需要将 || 更改为 &&,因为如果它们(iPod、iPad、iPhone)都不匹配,它应该重定向。

    【讨论】:

      猜你喜欢
      • 2014-01-31
      • 2013-06-04
      • 2013-06-20
      • 1970-01-01
      • 1970-01-01
      • 2010-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多