deviceType
判断设备的类型可以通过navigator.userAgent 截取字符串 来判断;
如
- navigator.userAgent.match(/iPhone/i)) 将返回iPhone;
- navigator.userAgent.match(/iPhone/i)) 将返回 Android;
if((navigator.userAgent.match(/iPhone/i)) == "iPhone"){
alert('iphone');
}else if((navigator.userAgent.match(/iPhone/i))=="Android"){
alert('android ');
}
例子:
function deviceType(){
var deviceType = (navigator.userAgent.match(/iPad/i)) == "iPad" ? "iPad"
: (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? "iPhone"
: (navigator.userAgent.match(/Android/i)) == "Android" ? "Android"
: (navigator.userAgent.match(/BlackBerry/i)) == "BlackBerry" ? "BlackBerry"
: "null";
return deviceType;
}
浙公网安备 33010602011771号