js判断设备类型

 

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)) {}

posted @ 2016-03-24 17:32  wifix  阅读(1474)  评论(0编辑  收藏  举报