H5 获取手机设备信息
isEquipment(){
let UA = navigator.userAgent,
isAndroid = /android|adr|linux/gi.test(UA),
isIOS = /iphone|ipod|ipad/gi.test(UA) && !isAndroid,
isBlackBerry = /BlackBerry/i.test(UA),
isWindowPhone = /IEMobile/i.test(UA),
isMobile = isAndroid || isIOS || isBlackBerry || isWindowPhone;
return{
isAndroid: isAndroid,
isIOS: isIOS,
isMobile: isMobile,
isWeixin: /MicroMessenger/gi.test(UA),
isQQ: /QQ/gi.test(UA),
isPC: !isMobile,
isWeibo: /WeiBo/gi.test(UA)
}
},
// 获取手机类型
<script src="https://cdn.jsdelivr.net/npm/mobile-detect@1.4.4/mobile-detect.min.js"></script>
//判断数组中是否包含某字符串
Array.prototype.contains = function(needle) {
for (i in this) {
if (this[i].indexOf(needle) > 0)
return i;
}
return -1;
}
var device_type = navigator.userAgent; //获取userAgent信息
// document.write(device_type); //打印到页面
var md = new MobileDetect(device_type); //初始化mobile-detect
var os = md.os(); //获取系统
console.log(os)
var model = "";
if (os == "iOS") { //ios系统的处理
os = +md.version("iPhone");
console.log(os)
model = md.mobile();
} else if (os == "AndroidOS") { //Android系统的处理
os = md.os() + md.version("Android");
var sss = device_type.split(";");
var i = sss.contains("Build/");
if (i > -1) {
model = sss[i].substring(0, sss[i].indexOf("Build/"));
}
}
// alert(os + "---" + model);//打印系统版本和手机型号
console.log(model + '||' + os, '打印系统版本和手机型号')
// 获取手机类型结束