| js用来区别IE与其他浏览器及IE6-8之间的方法。 1、document.all2、!!window.ActiveXObject;
 使用方法如下: if (document.all){alert(”IE浏览器”);
 }else{
 alert(”非IE浏览器”);
 }
 if (!!window.ActiveXObject){alert(”IE浏览器”);
 }else{
 alert(”非IE浏览器”);
 }
 下面是区别IE6、IE7、IE8之间的方法: var isIE=!!window.ActiveXObject;var isIE6=isIE&&!window.XMLHttpRequest;
 var isIE8=isIE&&!!document.documentMode;
 var isIE7=isIE&&!isIE6&&!isIE8;
 if (isIE){
 if (isIE6){
 alert(”ie6″);
 }else if (isIE8){
 alert(”ie8″);
 }else if (isIE7){
 alert(”ie7″);
 }
 }
 首先我们确保这个浏览器为IE的情况下,进行了在一次的检测,如果你对此有怀疑,可以测试一下。 我这里就直接使用在判断中了,你也可以将他们先进行声明成变量进行使用。据说火狐以后也会加入document.all这个方法,所以建议使用第二种方法,应该会安全一些。 |