Android模拟器浏览器检测
-
20-09-2019 - |
题
我正在开发一个网站的移动版本。我目前使用此Javascript来检测和用户重定向:
if((navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/Android/i)) ||
(navigator.userAgent.match(/iPod/i)))
{
window.location = "http://sitename.com/m/";
}
正常工作与iPhone和iPod,但与Android没有成功。我使用Eclipse中的Android模拟器。我没有一个Android小工具来实际测试一下。
我是不是做错了什么?有同样的问题的人?
解决方案
您应该使用 location.replace ,而不是 window.location的搜索结果 例如:
if( (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/Android/i)) || (navigator.userAgent.match(/iPod/i)) ) {
location.replace("http://sitename.com/m/");
}
我用这个代码和它的工作原理上iphone / iTouch的和Android手机/装置
其他提示
下面是矿JavaScript函数来检测Android装置:
function isAndroid() {
var ua = navigator.userAgent;
return ua.match(/Android/)
|| ua.match(/Dalvik/)
|| ua.match(/GINGERBREAD/)
|| ua.match(/Linux;.*Mobile Safari/)
|| ua.match(/Linux 1\..*AppleWebKit/)
};
window.location的不Android的工作?真?似乎工作得很好,我在Android 2.3.4。安卓的什么版本(S)没有你们使用,你不能让window.location的在浏览器中成功地加载新的网址是什么?
不隶属于 StackOverflow