参考 http://www.cnblogs.com/carekee/articles/1854674.html
通过userAgent判断浏览器的类型和版本是比较稳定的方式,这样做的效率没有根据各浏览器的特有特征判断的高。
var userAgent = navigator.userAgent.toLowerCase();
获取各浏览器的userAgent信息
IE10
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; .net4.0c; infopath.3)
chrome
mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.17 (khtml, like gecko) chrome/24.0.1312.57 safari/537.17
firefox
mozilla/5.0 (windows nt 6.1; wow64; rv:17.0) gecko/20100101 firefox/17.0
opera
opera/9.80 (windows nt 6.1; wow64) presto/2.12.388 version/12.15
safari
mozilla/5.0 (windows nt 6.1; wow64) applewebkit/534.57.2 (khtml, like gecko) version/5.1.7 safari/534.57.2
var userAgent = navigator.userAgent.toLowerCase();
//document.write(userAgent);
var browser =
(browser = userAgent.match(/qqbrowser\/([\d.]+)/))?"qqbrowser/"+browser[1]:
(browser = userAgent.match(/se\s+2.x/))?"sogou/2.x": //sougou
(browser = userAgent.match(/msie\s+([\d.]+)/))?"msie/"+browser[1]: //ie
(browser = userAgent.match(/chrome\/([\d.]+)/))?"chrome/"+browser[1]: //chrome
(browser = userAgent.match(/firefox\/([\d.]+)/))?"firefox/"+browser[1]: //firefox
(browser = userAgent.match(/version\/([\d.]+)\s+safari\/([\d.]+)/))?"safari/"+browser[1]: //safari
(browser = userAgent.match(/opera\/([\d.]+)([\w\W]+)version\/([\d.]+)/))?"opera/"+browser[3]: //opera
"other browser";
document.write(browser);
以上方法可以查看浏览器的版本和类型。