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;
}
posted on 2015-04-30 16:57  ทดสอบ  阅读(240)  评论(0)    收藏  举报