function KindOfBrowser() {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器
var isChrome = userAgent.indexOf("Chrome") > -1; //判断是否Chrome浏览器
if (isIE) {//IE
var IE5 = IE55 = IE6 = IE7 = IE8 = IE9 = false;
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
IE55 = fIEVersion == 5.5;
IE6 = fIEVersion == 6.0;
IE7 = fIEVersion == 7.0;
IE8 = fIEVersion == 8.0;
IE9 = fIEVersion == 9.0;
if (IE55) {
return "IE55";
}
else if (IE6) {
return "IE6";
}
else if (IE7) {
return "IE7";
}
else if (IE8) {
return "IE8";
}else if(IE9){
return "IE9";
}
}
else {
if (isFF) {
return "FF";
}
else if (isOpera) {
return "Opera";
}
else if (isChrome) {
return "Chrome";
}
}
}//KindOfBrowser() end
JavaScript判断浏览器种类
最新推荐文章于 2019-03-31 18:19:17 发布