Javascript 如何使用userAgent识别android和linux用户

Javascript 如何使用userAgent识别android和linux用户,javascript,android,linux,Javascript,Android,Linux,在我的桌面网站上,我获得了以下代码,用于将移动用户重定向到我网站的移动版本: <script type="text/javascript"> <!-- if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { location.replace("http://YOUR-MOBILE-SITE.com"); } --> </script> 应

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

<script type="text/javascript">
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
{
   location.replace("http://YOUR-MOBILE-SITE.com");
}
-->
</script>
应该用什么来代替/android/和/blackberry/


如何在linux上实现这一点/linux/?

使用媒体查询以特定宽度为目标,但不以设备为目标。 你可以使用不同分辨率和屏幕尺寸的手机、平板电脑、智能手机和半智能手机运行android。你也可以在Android上运行任意数量的浏览器,比如firefox

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

如果您坚持使用用户代理,请查看此链接以获取签名:

@media (max-width:320px){
///codezz
}
@media (max-width:1024px){
///codezz
}
    if(navigator.userAgent.indexOf('Android') > 0){
    //    runcodez
   };
    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...
    }