2019獨角獸企業重金招聘Python工程師標準>>>
開始之前 在以前很長一段時間里, 為了做前端的瀏覽器兼容而去利用 UA 判定瀏覽器類型(特別是IE)是很常見的 但如今都提倡利用 Features Detection 來處理兼容的問題, UA 判定的工作越來越少了 角度轉換一下, 現在不是為了做特性的兼容, 而是為了業務的兼容, 這類業務的兼容尤為多 我們需要給用戶一個 APP 下載的二維碼, 而不單獨列出各平臺的下載鏈接 二維碼只有一個, 跳到一個介紹頁, 下載跳轉按鈕只有一個 需要對 Android 和 iOS 平臺做區分 由于 QQ 和 微信 內的 WebView 有下載限制, 所以這里也需要做特殊處理
各類參考 NavigatorID.userAgent - Web API 接口| MDN 瀏覽器野史 UserAgent列傳(上) 瀏覽器野史 UserAgent列傳(下) MYIP.MS 其他人的收集1 其他人的收集2
收集到的信息 多數的信息都是自己收集的, 設備沒那么多, 所以不太全, 顧及了常用的 少部分是引用自上面的參考, 如 360SE 和 360EE, 360被公司封鎖了 自己也懶得去安裝那么多瀏覽器測試
// Ubuntu 16.04 Chrome
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36
// Ubuntu 16.04 Firefox
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0// Mac OS X Safari
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4
// Mac OS X Chrome
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
// Mac OS X Firefox
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0// Windows 10 Chrome
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
// Windows 10 Firefox
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
// Windows 10 Edge
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586
// Windows 10 IE11
Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; rv:11.0) like Gecko
// 下面是模擬出來的結果
// Windows 10 IE10
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)
// Windows 10 IE9
Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
// Windows 10 IE8
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)
// Windows 10 IE7
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
// Windows 10 IE6
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) // Windows 8.1 Chrome
Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
// Windows 8.1 IE11
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; rv:11.0) like Gecko
// Windows 8.1 LBBROWSER
Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.154 Safari/537.36 LBBROWSER
// Windows 8.1 LBBROWSER IE
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; LBBROWSER; rv:11.0) like Gecko
// Windows 8.1 360SE - Chrome
Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML like Gecko) Chrome/31.0.1650.63 Safari/537.36 QIHU 360SE
// Windows 8.1 360SE - IE
Mozilla/5.0 (compatible; MSIE 11.0; Windows NT 6.3; Trident/7.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; WebMoney Advisor; 360SE)// Windows 7 Chrome
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
// Windows 7 IE11
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; rv:11.0) like Gecko
// Windows 7 UC - IE
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0; UBrowser/5.6.12860.10) like Gecko
// Windows 7 UC - Chrome
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 UBrowser/5.6.12860.10 Safari/537.36
// Windows 7 360EE
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11 QIHU 360EE// 以下是移動端的
// Nexus5X QQ
Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MTC19T; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/50.0.2661.86 Mobile Safari/537.36 V1_AND_SQ_6.3.0_348_YYB_D QQ/6.3.0.2730 NetType/WIFI WebP/0.4.1 Pixel/1080
// Nexus5X WX
Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MTC19T) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036519 Safari/537.36 MicroMessenger/6.3.16.64_r75b3df2.780 NetType/WIFI Language/zh_CN
// Nexus5X Chrome
Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MTC19T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.89 Mobile Safari/537.36// iPhone 6s QQ
Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13F69 QQ/6.3.5.437 V1_IPH_SQ_6.3.5_1_APP_A Pixel/750 Core/UIWebView NetType/WIFI Mem/38
// iPhone 6s WX
Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13F69 MicroMessenger/6.3.16 NetType/WIFI Language/zh_CN
// iPhone 6s Safari
Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13F69 Safari/601.1
// iPhone 6s UC
Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/13F69 UCBrowser/10.9.15.793 Mobile// iPhone 6 QQ
Mozilla/5.0 (iPhone; CPU iPhone OS 9_3 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13E233 QQ/6.3.5.437 V1_IPH_SQ_6.3.5_1_APP_A Pixel/750 Core/UIWebView NetType/WIFI Mem/160
// iPhone 6 WX
Mozilla/5.0 (iPhone; CPU iPhone OS 9_3 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13E233 MicroMessenger/6.3.16 NetType/WIFI Language/zh_CN
// iPhone 6 Safari
Mozilla/5.0 (iPhone; CPU iPhone OS 9_3 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13E233 Safari/601.1
// iPhone 6 QQ Browser
Mozilla/5.0 (iPhone 6; CPU iPhone OS 9_3 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/6.0 MQQBrowser/6.7 Mobile/13E233 Safari/8536.25 MttCustomUA/2// MI 4 QQ
Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; MI 4LTE Build/KTU84P) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.4 TBS/025489 Mobile Safari/533.1 V1_AND_SQ_6.3.3_358_YYB_D PA QQ/6.3.3.2755 NetType/WIFI WebP/0.3.0 Pixel/1080
// MI 4 WX
Mozilla/5.0 (Linux; Android 4.4.4; MI 4LTE Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036215 Safari/537.36 MicroMessenger/6.3.18.800 NetType/WIFI Language/zh_CN
// MI 4 Chrome
Mozilla/5.0 (Linux; Android 4.4.4; MI 4LTE Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.95 Mobile Safari/537.36
// MI 4 UC
Mozilla/5.0 (Linux; Android 4.4.4; MI 4LTE Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36 UCBrowser/10.0.0.538
// MI 4 QQ browser
Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; MI 4LTE Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 Chrome/37.0.0.0 MQQBrowser/6.4 Mobile Safari/537.36// 以下是模擬的
// Ubuntu 16.04 Chrome - iPhone4
Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
// Ubuntu 16.04 Chrome - iPhone5
Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
// Ubuntu 16.04 Chrome - iPhone6
Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
// Ubuntu 16.04 Chrome - iPhone6 plus
Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
// Ubuntu 16.04 Chrome - iPad
Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
// Ubuntu 16.04 Chrome - iPad Mini
Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1// Ubuntu 16.04 Chrome - Nexus6P ???
Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36
// Ubuntu 16.04 Chrome - Nexus6
Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36
// Ubuntu 16.04 Chrome - Nexus5X ???
Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36
// Ubuntu 16.04 Chrome - Nexus5
Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36
// Ubuntu 16.04 Chrome - Nexus7
Mozilla/5.0 (Linux; Android 4.3; Nexus 7 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Safari/537.36
// Ubuntu 16.04 Chrome - Nexus10
Mozilla/5.0 (Linux; Android 4.3; Nexus 10 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Safari/537.36// Ubuntu 16.04 Chrome - Galaxy S5
Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36
// Ubuntu 16.04 Chrome - Galaxy S3
Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
// Ubuntu 16.04 Chrome - Galaxy Note3
Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30// Ubuntu 16.04 Chrome - Microsoft Lumia 950
Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263
// Ubuntu 16.04 Chrome - Microsoft Lumia 550
Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 550) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263
分析結果 如果只是要簡單地處理下, 并不在乎大小, 那么到 github 上找找就好, 比如這個: hgoebl/mobile-detect.js faisalman/ua-parser-js 這些庫里常常會收集了很多 UA 的特性, 功能可以說很完善, 但也常常跟不上設備更新的速度
而很多時候, 我們并不需要那么大而全的工具, 偏向于自己簡單地處理下
###總結一些關鍵字 Windows NT Windows NT 10.0 : Windows 10 Windows NT 6.3 : Windows 8.1 Windows NT 6.2 : Windows 8 Windows NT 6.1 : Windows 7 Windows NT 6.0 : Windows Vista Windows NT 5.2 : Windows 2003 Windows NT 5.1 : Windows XP Windows NT 5.0 : Windows 2000
userAgent = appCodeName/appVersion number (Platform; Security; OS-or-CPU; Localization; rv: revision-version-number) product/productSub Application-Name Application-Name-version
Security N: 表示無安全加密 I: 表示弱安全加密 U: 表示強安全加密
###判斷 Android 最明顯的是利用關鍵字: "Android" 可是看細致了會發現 Windows Phone 的 UA 也會加入 "Android" 關鍵字 所以得過濾掉 Windows Phone
const ua = navigator.userAgent.toLowerCase();
//let isAndroid = /android/i.test(ua)
###判斷 iOS
轉載于:https://my.oschina.net/keywindy/blog/686514
總結
以上是生活随笔 為你收集整理的UA Detect 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。