JavaScript判断浏览器及其版本信息

通过window.navigator来判断:

 1 function getBrowserInfo(){
 2     var Info = {};
 3     var str = window.navigator.userAgent.toLowerCase();
 4     var bReg =/(msie|firefox|chrome|opera|version).*?([\d.]+)/;
 5     var infoArr = str.match(bReg);
 6     Info.browser = infoArr[1].replace(/version/, "safari");
 7     Info.ver = infoArr[2];
 8     return Info;
 9 }
10 var BomInfo = getBrowserInfo();
11 
12 document.write(BomInfo.browser);
13 document.write("</br>");
14 document.write(BomInfo.ver);

 

posted @ 2017-01-20 16:43  富录  阅读(451)  评论(0编辑  收藏  举报