0

在我的桌面网站上,我得到了将移动用户重定向到我网站的移动版本的代码:

<script type="text/javascript">
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
{
   location.replace("http://YOUR-MOBILE-SITE.com");
}
-->
</script>

这适用于iOS,但我想要类似的东西

else if (navigator.userAgent.match(/Android/i))
{
    location.replace...
}
else if (navigator.userAgent.match(/blackberry/i))
{
    location...
}

应该用什么来代替 /android/ 和 /blackberry/?

以及如何用linux做到这一点?/linux/?

4

2 回答 2

0

使用媒体查询来定位特定宽度而不是设备。您拥有运行 android 的具有不同分辨率和屏幕尺寸的电视、平板电脑、智能手机、半智能手机。您还可以在 Android 上运行任意数量的浏览器,例如 firefox。

@media (max-width:320px){
///codezz
}
@media (max-width:1024px){
///codezz
}

ETC'

如果您坚持使用用户代理执行此操作,请参阅此链接以获取签名: https ://developers.google.com/chrome/mobile/docs/user-agent

    if(navigator.userAgent.indexOf('Android') > 0){
    //    runcodez
   };
于 2013-06-26T10:11:18.677 回答
0
    else if (navigator.userAgent.indexof("Android")!=-1)
    {
        location.replace...
    }
    //User Agent in BlackBerry 6 and BlackBerry 7/BlackBerry Device Software 4.2 to 5.0
    else if (navigator.userAgent.indexof("BlackBerry") ! = -1)
    {
        location...
    }
    //User Agent in BlackBerry Tablet OS
    else if (navigator.userAgent.indexof("PlayBook") ! = -1)
    {
        location...
    }
    //User Agent in BlackBerry 10
    else if (navigator.userAgent.indexof("BB10") ! = -1)
    {
        location...
    }
else if (navigator.userAgent.indexof("linux") ! = -1)
    {
        location...
    }
于 2013-06-26T10:14:01.807 回答