判断useragent是来自普通pc,还是来自移动设备。普通pc打开index-pc.html,移动设备打开index-m.html
var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(iphone|ipod|ipad|android)/);
if(agentID){
if(agentID.indexOf("iphone")>=0 || agentID.indexOf("ipod")>=0 || agentID.indexOf("ipad")>=0 || agentID.indexOf("android")>=0){
window.location="index-m.html";
}
else{
window.location="index-pc.html";
}
}
else{
window.location="index-pc.html";
}

本文介绍了一种通过分析UserAgent字符串来判断用户设备类型的方法,并据此实现不同设备访问不同页面的功能。主要通过匹配iPhone、iPod、iPad及Android等关键字来区分移动设备与普通PC。
1568

被折叠的 条评论
为什么被折叠?



