Vit*_*tor 7 browser android android-emulator
我正在开发一个网站的移动版本.我目前正在使用此Javascript来检测和重定向用户:
if((navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/Android/i)) ||
(navigator.userAgent.match(/iPod/i)))
{
window.location = "http://sitename.com/m/";
}
Run Code Online (Sandbox Code Playgroud)
适用于iPhone和iPod,但Android没有成功.我在Eclipse中使用Android模拟器.我没有Android小工具来实际测试它.
难道我做错了什么?谁有同样的问题?
小智 12
您应该使用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/");
}
Run Code Online (Sandbox Code Playgroud)
我使用这个代码,它适用于iPhone/itouch和Android手机/设备.
| 归档时间: |
|
| 查看次数: |
13668 次 |
| 最近记录: |