https://blog.csdn.net/qq_33183172/article/details/98961419
Determine what mobile phone brand is currently open
It is necessary to know what platform the page is opened through in the business, and the userAgent is used in the front end to judge. The following text involves three categories: mainstream mobile phone brand judgment methods, whether to open on WeChat, whether to open on PC or Pad.
Determine whether the business is opened by iphone, Huawei, Xiaomi, oppo, view, or Samsung
function judgeBrand(sUserAgent) {
var isIphone = sUserAgent.match(/iphone/i) == "iphone";
var isHuawei = sUserAgent.match(/huawei/i) == "huawei";
var isHonor = sUserAgent.match(/honor/i) == "honor";
var isOppo = sUserAgent.match(/oppo/i) == "oppo";
var isOppoR15 = sUserAgent.match(/pacm00/i) == "pacm00";
var isVivo = sUserAgent.match(/vivo/i) == "vivo";
var isXiaomi = sUserAgent.match(/mi\s/i) == "mi ";
var isXiaomi2s = sUserAgent.match(/mix\s/i) == "mix ";
var isRedmi = sUserAgent.match(/redmi/i) == "redmi";
var isSamsung = sUserAgent.match(/sm-/i) == "sm-";
if (isIphone) {
return 'iphone';
} else if (isHuawei || isHonor) {
return 'huawei';
} else if (isOppo || isOppoR15) {
return 'oppo';
} else if (isVivo) {
return 'vivo';
} else if (isXiaomi || isRedmi || isXiaomi2s) {
return 'xiaomi';
} else if (isSamsung) {
return 'samsung';
} else {
return 'default';
}
}
var brand = judgeBrand(navigator.userAgent.toLowerCase()); //调用机型判断
///使用navigator.userAgent.toLowerCase()判断登陆端是pc还是手机
Use navigator.userAgent.toLowerCase() to determine whether the login terminal is a pc or a mobile phone
https://blog.csdn.net/xiaozhi_2016/article/details/52288556
Determine whether the business is opened by WeChat
function isWeChat() {
var ua = navigator.userAgent.toLowerCase();
return (/micromessenger/.test(ua)) ? true : false;
}
Determine on which platform to open pad, pc, mobile phone
function checkAgent() {
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
if (!(bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM || bIsIpad)) {
return 'pc';
} else if(bIsIpad){
return 'pad';
}else{
return 'phone';
}
}