这里引用http://www.useragentstring.com/ 的用户代理报告来解释一下用户代理中的字段都是表示什么意思:
chrome:
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36
firefox:
Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0
IE:
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Geck
移动端的代理检测:
safari
userAgent:Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B440 Safari/600.1.4
android浏览器
android系统中几乎全部杂牌国产浏览器都是使用的webkit的内核,opera在新版本上也从pesto转向webkit,截取一二示意:
1、chrome(android版)
Mozilla/5.0 (Linux; Android 4.1.1; MI 2 Build/JRO03L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36
小米内置
Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; MI 2S Build/JRO03L) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 XiaoMi/MiuiBrowser/2.1.1
3、mercury浏览器:
Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; MI 2S Build/JRO03L) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
4、opera浏览器
旧版:
Opera/9.80 (Android; Opera Mini/7.8.35885/35.5464; U; zh) Presto/2.8.119 Version/11.10
新版:
Mozilla/5.0 (Linux; U; Android 4.1.1; zh-CN; MI 2S Build/JRO03L) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 OPR/10.2.5.89953 Mobile Safari/534.30
windows phone:
自带IE11:
Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Nokia 520) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537
UC:
Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Nokia 520) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537 UCBrowser/4.2.1.541 Mobile
summary:
关于用户代理更多的信息,可以查看http://useragentstring.com/pages/useragentstring.php
代理检测(参考zmobile.js):
var ua = function ( ua, appVersion, platform ) {
return {
// win系列
win32 : platform === "Win32",
ie : /MSIE ([^;]+)/.test( ua ),
ieMobile : window.navigator.msPointerEnabled,
ieVersion : Math.floor( (/MSIE ([^;]+)/.exec( ua ) || [0, "0"])[1] ),
// ios系列
ios : (/iphone|ipad/gi).test( appVersion ),
iphone : (/iphone/gi).test( appVersion ),
ipad : (/ipad/gi).test( appVersion ),
iosVersion : parseFloat( (‘‘ + (/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec( ua ) || [0, ‘‘])[1])
.replace( ‘undefined‘, ‘3_2‘ ).replace( ‘_‘, ‘.‘ ).replace( ‘_‘, ‘‘ ) ) || false,
safari : /Version\//gi.test( appVersion ) && /Safari/gi.test( appVersion ),
uiWebView : /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test( ua ),
// 安卓系列
android : (/android/gi).test( appVersion ),
androidVersion : parseFloat( "" + (/android ([0-9\.]*)/i.exec( ua ) || [0, ‘‘])[1] ),
// chrome
chrome : /Chrome/gi.test( ua ),
chromeVersion : parseInt( ( /Chrome\/([0-9]*)/gi.exec( ua ) || [0, 0] )[1], 10 ),
// 内核
webkit : /AppleWebKit/.test( appVersion ),
// 其他浏览器
uc : appVersion.indexOf( "UCBrowser" ) !== -1,
Browser : / Browser/gi.test( appVersion ),
MiuiBrowser : /MiuiBrowser/gi.test( appVersion ),
// 微信
MicroMessenger : ua.toLowerCase().match( /MicroMessenger/i ) == "micromessenger",
// 其他
canTouch : "ontouchstart" in document
};
}( navigator.userAgent, navigator.appVersion, navigator.platform );