网页制作web前端之家文章简介:JS判断IE,FF等浏览器类型.

第一种,只区分浏览器,不考虑版本function myBrowser(){var userAgent =
navigator.userAgent; //取得浏览器的userAgent字符串var isOpera =
userAgent.indexOf > -1;if {return “Opera”}; //判断是否Opera浏览器if
(userAgent.indexOf > -1){return “FF“;} //判断是否Firefox浏览器if
(userAgent.indexOf > -1){return “Safari”;} //判断是否Safari浏览器if
(userAgent.indexOf(“compatible”) > -1 && userAgent.indexOf > -1 &&
!isOpera){return “IE”;} ;
//判断是否IE浏览器}//以下是调用上面的函数if==”IE”){alert;}if==”FF“){alert(“我是
Firefox”);}if==”Opera”){alert;}if==”Safari”){alert(“我是
Safari”);}第二种,区分浏览器,并考虑IE5.5 6 7 8function myBrowser(){var
userAgent = navigator.userAgent; //取得浏览器的userAgent字符串var
isOpera = userAgent.indexOf > -1; //判断是否Opera浏览器var isIE =
userAgent.indexOf(“compatible”) > -1 && userAgent.indexOf > -1 &&
!isOpera ; //判断是否IE浏览器var isFF = userAgent.indexOf > -1 ;
//判断是否Firefox浏览器var isSafari = userAgent.indexOf > -1 ;
//判断是否Safari浏览器if{var IE5 = IE55 = IE6 = IE7 = IE8 = false;var
reIE = new RegExp(“MSIE ;reIE.test;var fIEVersion =
parseFloat(RegExp[“$1”]);IE55 = fIEVersion == 5.5 ;IE6 = fIEVersion ==
6.0 ;IE7 = fIEVersion == 7.0 ;IE8 = fIEVersion == 8.0 ;if{ return
“IE55”; }if{ return “IE6”; }if{ return “IE7”; }if{ return “IE8”;
}}//isIE endif{ return “FF“; }if{ return “Opera”; }}//myBrowser()
end//以下是调用上面的函数if==”FF“){alert(“我是
Firefox”);}if==”Opera”){alert;}if==”Safari”){alert(“我是
Safari”);}if==”IE55″){alert;}if==”IE6″){alert;}if==”IE7″){alert;}if==”IE8″){alert;}

相关文章

网站地图xml地图