javascript检测浏览器精简版

代码
 1 /*written by xp in 8z at Mar 4,2010.QQ:251089096*/
 2 var sUserAgent = navigator.userAgent;
 3 var isIE=isIE6=isIE7=isIE8=isFirefox=false;
 4 if(sUserAgent.indexOf("MSIE"> -1){
 5 isIE = true;
 6 var version = sUserAgent.substr(sUserAgent.indexOf("MSIE")+5,3);
 7 if(version == "6.0"){isIE6=true;}
 8 if(version == "7.0"){isIE7=true;}
 9 if(version == "8.0"){isIE8=true;}
10 }
11 if(sUserAgent.indexOf("Firefox"> -1){isFirefox=true;}

使用指引:

 1 if(isIE)
 2 {
 3    语句体
 4 }
 5 if(isIE6)
 6 {
 7    语句体
 8 }
 9 if(isIE7)
10 {
11    语句体
12 }
13 if(isIE8)
14 {
15    语句体
16 }
17 if(isFirefox)
18 {
19    语句体
20 }
21 
原文地址:https://www.cnblogs.com/xiaopin/p/1678572.html