用user-agent来判断感觉不是很准确,有没有其他的方法?
2 回答
MM们
TA贡献1886条经验 获得超2个赞
varevents=navigator.userAgent;console.log(navigator.userAgent);console.log(navigator.appVersion);console.log(navigator)if(events.indexOf('Android')>-1||events.indexOf('Linux')>-1||events.indexOf('Adr')>-1){console.log("安卓手机");}elseif(events.indexOf('iPhone')>-1){//根据尺寸进行判断苹果的型号if(screen.height==812&&screen.width==375){console.log("苹果X");}elseif(screen.height==736&&screen.width==414){console.log("iPhone7P-iPhone8P-iPhone6");}elseif(screen.height==667&&screen.width==375){console.log("iPhone7-iPhone8-iPhone6");}elseif(screen.height==568&&screen.width==320){console.log("iPhone5");}else{console.log("iPhone4");}}elseif(events.indexOf('WindowsPhone')>-1){console.log("诺基亚手机");}elseif(events.indexOf("iPad")>-1){console.log("平板");}
添加回答
举报
0/150
提交
取消