原理:通过 navigator.userAgent 中包含的关键字进行正则表达式判断
var u = navigator.userAgent;
var isIphone = u.indexOf('iPhone') > -1;
var isPad = u.indexOf('iPad') > -1;
var isAndroid = u.indexOf('Android') > -1;
然后通过判断进行网页加载
$(document).ready(function () {
try{
if ( isIphone || isAndroid) {
window.location.href="mobile.html";
}else if (isPad) {
window.location.href="pad.html";
}else {
window.location.href="other.html";
}
}catch(e){}
});
各平台userAgent信息,仅供参考:
iPhone : Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/5