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.';
}