• js获取判断苹果手机机型


    原先获取不了苹果系列的型号,但转换思路,先判断是否是苹果,再用分辨率获取型号

    //获取手机型号函数begin
    function getPhoneType(){ 
    //正则,忽略大小写
    var pattern_phone = new RegExp("iphone","i");
    var pattern_android = new RegExp("Android","i");
    var userAgent = navigator.userAgent.toLowerCase();
    var isAndroid = pattern_android.test(userAgent);
    var isIphone = pattern_phone.test(userAgent);
    var phoneType="phoneType";
    if(isAndroid){ 
    var zh_cnIndex = userAgent.indexOf("-");
    var spaceIndex = userAgent.indexOf("build",zh_cnIndex+4);
    var fullResult = userAgent.substring(zh_cnIndex,spaceIndex);
    phoneType=fullResult.split(";")[1];
    }else if(isIphone){ 
    //6   w=375    6plus w=414   5s w=320     5 w=320
    var wigth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    if(wigth>400){ 
    phoneType = "iphone6 plus";
    }else if(wigth>370){ 
    phoneType = "iphone6";
    }else if(wigth>315){ 
    phoneType = "iphone5 or iphone5s";
    }else{ 
    phoneType = "iphone 4s";
    }
    }else{ 
    phoneType = "您的设备太先进了";
    }
    return phoneType;
    }
    //end

    //手机touch事件开始

    <script>
    function load (){
        document.addEventListener('touchstart',touch, false);
        document.addEventListener('touchmove',touch, false);
        document.addEventListener('touchend',touch, false);
        function touch (event){
            var event = event || window.event;
            var oInp = document.getElementById("inp");
            switch(event.type){
                case "touchstart":
                    oInp.innerHTML = "Touch started (" + event.touches[0].clientX + "," + event.touches[0].clientY + ")";
                    break;
                case "touchend":
                    oInp.innerHTML = "<br>Touch end (" + event.changedTouches[0].clientX + "," + event.changedTouches[0].clientY + ")";
                    break;
                case "touchmove":
                    event.preventDefault();
                    oInp.innerHTML = "<br>Touch moved (" + event.touches[0].clientX + "," + event.touches[0].clientY + ")";
                    break;
            }
        }
    }
    window.addEventListener('load',load, false);
    </script>

    //touch事件结束

  • 相关阅读:
    【django 】后台在线查看文件,下载文件的配置
    【Python小随笔】Pandas读取每一行数据
    【Django】 admin创建普通用户
    【Django】 原生上传文件,后台接收文件
    Visual Studio Code 配置C、C++ 文件debug调试环境
    华为 matebook x pro 使用U盘启动winpe系统
    记微信第三方平台通过ticket 并解密 然后授权相关接口/获取令牌 获取component_access_token
    C#中字符串的修改
    HTML Table 合并单元格
    TortoiseGit小乌龟安装配置及使用
  • 原文地址:https://www.cnblogs.com/heroine/p/6710848.html
Copyright © 2020-2023  润新知