码迷,mamicode.com
首页 > Web开发 > 详细

js判断设备类型

时间:2016-03-24 18:13:56      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

 

1.检测安卓,苹果和windows phone的手机

var ua = navigator.userAgent;
var url;

if(ua.match(/Windows\sPhone/i) !=null){
    console.log(‘this is Windowsphone ‘);
}
else if(ua.match(/iPhone|iPod/i) != null){
    url = "itms-apps://itunes.apple.com/app/id959587493";
    window.setTimeout(function () {
        window.location.href = url;
    },10);
}
else if(ua.match(/Android/i) != null){
    url = "http://a.app.qq.com/o/simple.jsp?pkgname=com.electric.chargingpile";
    window.setTimeout(function () {
        window.location.href = url;
    },10);
}

var ua = navigator.userAgent;
        var url;

        if(ua.match(/Windows\sPhone/i) !=null){
            console.log(‘this is Windowsphone ‘);
        }
        else if(ua.match(/iPhone|iPod/i) != null){
            url = "itms-apps://itunes.apple.com/app/id959587493";
            window.setTimeout(function () {
                window.location.href = url;
            },10);
        }
        else if(ua.match(/Android/i) != null){
            url = "http://a.app.qq.com/o/simple.jsp?pkgname=com.electric.chargingpile";
            window.setTimeout(function () {
                window.location.href = url;
            },10);
        }

判断设备为微信内的浏览器

2.if ((/MicroMessenger/i).test(window.navigator.userAgent)) {}

js判断设备类型

标签:

原文地址:http://www.cnblogs.com/isdom/p/webclips043.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!