第一种:
if(window.addEventListener){
-
alert("not ie"); -
}else if(window.attachEvent){ -
alert("is ie"); -
}else{ -
alert("这种情况发生在不支持DHTML的老版本浏览器(现在一般都支持)") -
}
第二种:
if(document.all){
-
alert("IE6"); -
}else{ -
alert("not ie"); -
}
第三种:
var navigatorName = "Microsoft Internet Explorer";
-
var isIE = false; -
if( navigator.appName == navigatorName ){ -
isIE = true; -
alert("ie") -
}else{ -
alert("not ie") -
}
第四种:
if(!+[1,])alert("这是ie浏览器");
-
else alert("这不是ie浏览器");
第五种:
function isIE() { //ie? if (!!window.ActiveXObject || "ActiveXObject" in window) return true; else return false; } if(isIE()){ alert(isIE()) }else{ alert(isIE()) }
个人意见第五种最好用