在做移动端项目的时候,常常会遇到需要判断页面浏览终端的需求。要想判断是什么浏览器终端,先打印 navigator.userAgent 出来。所以收集了几种比较常用的方法:
if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { //IOS
??window.location.href = "https://itunes.apple.com/cn/app/fu-xing-zhi-hui-jia/id1081255502?mt=8";
}
else if(/(Android)/i.test(navigator.userAgent)) { ??? //安卓
??window.location.href = "http://www.fxzhjapp.com/WisdomHouse.apk";
}
else {
??alert("请用手机下载客户端!");
}
function is_weixn(){ //微信判断
???var ua = navigator.userAgent.toLowerCase();
???if(ua.match(/MicroMessenger/i)=="micromessenger") {
???????return true;
???} else {
???????return false;
???}
}
function is_qq(){ //QQ
???if(navigator.userAgent.toLowerCase().indexOf("mqqbrowser") > -1 && navigator.userAgent.toLowerCase().indexOf("QQ/") > -1){
???????$(‘.wxImg‘).css(‘display‘,‘block‘);
???????return true;
???}
}
以上就是几种判断浏览终端的常见方法。
PS:如何判断是否为APP外部或者内部
如果页面在APP内部打开会有一个特定的值,如果没有就是外部。一般前端不用做这种操作,PHP方面就直接判断了。如果非要判断,就让APP方面提供值就OK了。
jS判断浏览器终端
原文地址:http://www.cnblogs.com/qiuchuanji/p/7650304.html