记录华为鸿蒙系统中的userAgent输出和判断华为和小米手机的方法
当我们执行:
navigator.userAgent.toLowerCase()
在微信中:
mozilla/5.0 (linux; android 12; jad-al00 build/huaweijad-al00; wv)
applewebkit/537.36 (khtml, like gecko) version/4.0
chrome/86.0.4240.99 xweb/4375 mmwebsdk/20221012 mobile
safari/537.36 mmwebid/8647
micromessenger/8.0.30.2260(0x28001e55) wechat/arm64 weixin
nettype/wifi language/zh_cn abi/arm64
在华为默认的浏览器中:
mozilla/5.0 (linux; android 12; harmonyos; jad-al00; hmscore 6.8.0.332)
applewebkit/537.36 (khtml, like gecko) chrome/99.0.4844.88
huaweibrowser/13.0.0.310 mobile safari/537.36
另记录匹配是否是华为或者小米手机的方法:
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还是手机