Javascript 判断浏览器版本和名称
Posted 王仲春的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Javascript 判断浏览器版本和名称相关的知识,希望对你有一定的参考价值。
var agent = navigator.userAgent.toLowerCase(),
browserVersion = null,
browserSet = [‘msie‘,‘chrome‘,‘firefox‘,‘safari‘];
browserSet.forEach(function(item){
//eg:In chrome ,navigator.userAgent is "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/52.0.2743.116 Safari/537.36"
var res = agent.match(new RegExp(item + ‘/[\\d+\\.]\+‘));
if(res !== null){
browserVersion = res[0];
return false;
}
});
if(browserVersion === null){
//in IE11,navigator.userAgent is "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; InfoPath.3; rv:11.0) like Gecko"
if(‘ActiveXObject‘ in window){
browserVersion = ‘ie/11.0‘;
}
}
if(browserVersion === null){
browserVersion = ‘is not a standard explorer.‘;
}
以上是关于Javascript 判断浏览器版本和名称的主要内容,如果未能解决你的问题,请参考以下文章