猿问

如何用js判断iPhone5 iPhone 5S iPhone6 iPhone6 plus?

用user-agent来判断感觉不是很准确,有没有其他的方法?
UYOU
浏览 424回答 2
2回答

MM们

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("平板");}

扬帆大鱼

user-agent估计就能判断出是apple,用浏览器宽高应该能判断出来
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答