共计 1500 个字符,预计需要花费 4 分钟才能阅读完成。
ipad7 (13.4) 下各浏览器 userAgent
//chrome
Mozilla/5.0 (iPad; CPU OS 13_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/83.0.4103.88 Mobile/15E148 Safari/604.1
//TODO:safari
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15
//weixin
Mozilla/5.0 (iPad; CPU OS 13_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.14(0x17000e23) NetType/WIFI Language/zh_CN
//douyin
Mozilla/5.0 (iPad; CPU OS 13_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 aweme_11.7.0 JsSdk/2.0 NetType/WIFI Channel/App Store ByteLocale/zh Region/CN ByteFullLocale/zh-Hans-CN WKWebView/1
//weibo
Mozilla/5.0 (iPad; CPU OS 13_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Weibo (iPad7,12__weibo__10.6.0__ipad__os13.4)
//safari 根本没有什么辨认字符串了,只能用排除了
// 没思考 qq, 百度,360,uc 浏览器,有机会补充
function checkUA(isUA){
let ua = navigator.userAgent;
let uas = ua.toLowerCase();
let mobile = /mobile|tablet|ip(ad|hone|od)|android/i.test(uas);
let android = mobile && (uas.indexOf('android') > -1 || uas.indexOf('linux') > -1) || uas.indexOf('adr') > -1;
let ios = mobile && !android && /Mac OS/i.test(ua);
let iphone = ios && uas.indexOf('iphone') > -1;
let ipad = ios && !iphone;
let wx = /MicroMessenger/i.test(ua);
let chrome = (/CriOS/i.test(ua) || /Chrome/i.test(ua));
let tiktok = mobile && /aweme/i.test(ua);
let weibo = mobile && /Weibo/i.test(ua);
let safari = ios && !chrome && !wx && !weibo && !tiktok && /Safari|Macintosh/i.test(ua);
let res = {
ua,
mobile,
android,
ios,
wx,
chrome,
iphone,
ipad,
safari,
tiktok,
weibo
};
return isUA && res.hasOwnProperty(isUA) ? res[isUA] : res;
}
正文完
发表至: javascript
2020-07-11