纯网页开发的话用一下这个方法,我只是简单的用来根据不同的手机型号来做一些css样式的修改了。
var events = 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("安卓手机"); }else if(events.indexOf(‘iPhone‘)>-1){ //根据尺寸进行判断 苹果的型号 if(screen.height == 812 && screen.width == 375){ console.log("苹果X"); }else if(screen.height == 736 && screen.width == 414){ console.log("iPhone7P - iPhone8P - iPhone6"); }else if(screen.height == 667 && screen.width == 375){ console.log("iPhone7 - iPhone8 - iPhone6"); }else if(screen.height == 568 && screen.width == 320){ console.log("iPhone5"); }else{ console.log("iPhone4"); } }else if(events.indexOf(‘Windows Phone‘)>-1){ console.log("诺基亚手机"); }else if(events.indexOf("iPad")>-1){ console.log("平板"); }
或者可以用 window.screen.width 通过浏览器检测屏幕的宽度来判断这个值属于哪个手机尺寸范围
如何通过js判断手机型号 iphone5 iphone5s iphone6 iphone7等等
原文:https://www.cnblogs.com/duhui/p/11897670.html