【转】烂泥:关于国内浏览器的userAgent识别

本文由秀依林枫提供友情赞助,首发于烂泥行天下

IE10浏览器:appName:Microsoft Internet Explorer|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)

360浏览器:appName:Microsoft Internet Explorer|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)

360极速浏览器:appName:Microsoft Internet Explorer|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)

搜狗浏览器:appName:Microsoft Internet Explorer|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E; SE 2.X MetaSr 1.0)

##MetaSr

windows下的safar :appName:Netscape|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2

(safari在windows下已经停止开发了,也就是苹果已经抛弃windows下的浏览器市场了,在windows系统下用safari的用户也算得上奇葩了吧!)

mac下的safari:appName:Netscape|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1

  ##Safari 必须先检测chrome,猎豹,遨游等

chrome浏览器:appName:Netscape|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36 ##Chrome 必须先检测猎豹遨游等

遨游浏览器:appName:Netscape|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Maxthon/4.0.6.2000 Chrome/26.0.1410.43 Safari/537.1 ##Maxthon

QQ浏览器:appName:Microsoft Internet Explorer|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E; QQBrowser/7.3.9825.400) ##QQBrowser
fireFox 浏览器:appName:Netscape|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0 ##

猎豹浏览器:appName:Netscape|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.92 Safari/537.1 LBBROWSER ##LBBROWSER

百度浏览器:appName:Microsoft Internet Explorer|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; BIDUBrowser 2.x) ##BIDUBrowser

淘宝浏览器:appName:Netscape|—–|appCodeName:Mozilla|—–|userAgent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.11 TaoBrowser/3.0 Safari/536.11 ##TaoBrowser

关于浏览器识别的代码

function setIntestineBrowser(){

var userAgent = navigator.userAgent;

var browserKeyArr = [{

name:’搜狗’,

domKey:’sougou’,

agentKey:’MetaSr’

},{

name:’QQ’,

domKey:’qq’,

agentKey:’QQBrowser’

},

{

name:’猎豹’,

domKey:’liebao’,

agentKey:’LBBROWSER’

},{

name:’淘宝’,

domKey:’taobao’,

agentKey:’TaoBrowser’

},{

name:’遨游’,

domKey:’aoyou’,

agentKey:’Maxthon’

}];

for(var i = 0,length = browserKeyArr.length; i < length ; i++){

var pattern = new RegExp(browserKeyArr[i].agentKey);

if(pattern.test(userAgent)){

$(‘.collection-menu ul li[data-v=’ + browserKeyArr[i].domKey + ‘]’).click();

return ;

}

}

}

补充说明:由于国内浏览器用的内核多是国外的,所以很多特性无法与国外浏览器区分,所以要先检测国外浏览器,再检测国内浏览器。这样当国内浏览器没有找到匹配项时就是内核默认的国外浏览器。

未经允许不得转载:烂泥行天下 » 【转】烂泥:关于国内浏览器的userAgent识别

赞 (0) 打赏

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

支付宝扫一扫打赏

微信扫一扫打赏