在我的桌面网站上,我得到了以下代码,用于将移动用户重定向到我网站的移动版本:
<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/