js判断手机端(Android手机还是iPhone手机)

时间:2021-09-07 18:27:38
/**
* [isMobile 判断平台]
* @param test: 0:iPhone 1:Android
*/
function ismobile(test){
var u = navigator.userAgent, app = navigator.appVersion;
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?mobile")<){
try{
if(/iPhone|mac|iPod|iPad/i.test(navigator.userAgent)){
return '';
}else{
return '';
}
}catch(e){}
}
}else if( u.indexOf('iPad') > -){
return '';
}else{
return '';
}
};

使用方法:

var pla=ismobile(1);

如果pla返回的是0:iPhone 1:Android