用js判断 iPhone6 iPhone6 plus iphonex?

孤街醉人 提交于 2020-03-07 11:02:17

 

var events = navigator.userAgent;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){// 进行操作,改变样式

const obj = document.getElementById('sendxBtn')
obj.setAttribute("style", "padding:5px 10px 20px;")

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

  

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!