需求
在我们写项目时候, 经常会遇到限制打开页面的方式;那就需要我们去判断。网上有很多中方式,我给大家总结出来了
总结(解决)
// 是否微信浏览器 普通浏览器
if (/(micromessenger)/i.test(navigator.userAgent)) {
alert("微信");
} else {
alert("普通浏览器");
}
// 是否pc 手机
let client =/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
if (client) {
alert("手机");
} else {
alert("pc");
}
// 是否pc 手机+iPad
function isMobile(){
if(window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)) {
return true; // 手机+iPad
}else{
return false; // pc
}
}
// 是否APP环境 (本人没用过)
function getIsApp () {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/isapp/i) == "isapp") {
return true;
}
return fals