js判断设备类型
Posted wifix
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)) {}
以上是关于js判断设备类型的主要内容,如果未能解决你的问题,请参考以下文章