javascript - 如何使用userAgent识别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>

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

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

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

如何在 Linux 上做到这一点?/linux/?

最佳答案

    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...
    }

关于javascript - 如何使用userAgent识别android和linux用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17317122/

相关文章:

javascript - 在点击叠加层时更改叠加层中图像的不透明度

javascript - Spring stomp websockets with vue.js

javascript - React-Bootstrap 设置 FormControl Select 的值

java - 如何让连接线程保持 Activity 状态? (我需要使用守护进程吗?)

linux - 命令在终端而不是脚本中工作

linux - 使用 echo 命令将别名写入 bashrc 文件

javascript - 我可以获得当前被 knockout 绑定(bind)的元素列表吗?

java - androidcameraX API亮度问题

android - 在特定情况下未绘制 View

linux - 在linux中将制表符分隔的文件转换为csv的最快方法