JS判断当前手机型号

    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;
    }
时间: 2024-10-22 04:57:39

JS判断当前手机型号的相关文章

史上最简单,js并获取手机型号

原先获取不了苹果系列的型号,但转换思路,先推断是否是苹果,再用分辨率获取型号 //获取手机型号函数begin function getPhoneType(){ //正则,忽略大写和小写 var pattern_phone = new RegExp("iphone","i"); var pattern_android = new RegExp("android","i"); var userAgent = navigator.u

js判断是手机访问网站跳转

<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script> <script type="text/javascript">uaredirect("你的手机版网址");</script>

JS判断安卓手机是否装了某个app方法

做项目,头给了个任务,让用JS检测手机是否装了我们公司的app.如果装了则调起,没装则跳转到安装页面. 首先,我去了百度,发现百度上给的答案很乱,我就自己试,结果还是不行.IOS上百度的方法是可行的,亲们可以自己试试 现在 就说说安卓的吧,不废话了.代码: document.getElementById('openAppAnd').onclick = function(){           var ifr = document.getElementById("ifr");     

js判断是手机还是PC端

有时接触一些手机上的适应,需要知道是pc 还是移动端 function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; var flag = true; for (var v

JS判断用户手机是IOS还是Android

$(function () { var u = navigator.userAgent, app = navigator.appVersion; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 if (isAndroid) { alert("安卓机!"

判断iphone手机型号

#define isIPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) #define isIPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)]

js判断是手机访问还是电脑访问

<script type="text/javascript"> //平台.设备和操作系统 var system ={ win : false, mac : false, xll : false }; //检测平台 var p = navigator.platform; system.win = p.indexOf("Win") == 0; system.mac = p.indexOf("Mac") == 0; system.x11 =

JS判断是否是微信页面,判断手机操作系统(ios或android)并跳转到不同下载页面

JS判断客户端是否是iOS或者Android 参考:http://caibaojian.com/browser-ios-or-android.html 1 function is_weixin() { 2 var ua = window.navigator.userAgent.toLowerCase(); 3 if (ua.match(/MicroMessenger/i) == 'micromessenger') { 4 return true; 5 } else { 6 return fals

js 判断当前的手机系统类型

<script language="javascript"> window.onload = function () { alert("1"); var u = navigator.userAgent; if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机alert("安卓手机"); // window.location.href = "