IE浏览器的兼容性的判断

来源:互联网 发布:淘宝搜索排名规则2017 编辑:程序博客网 时间:2024/06/05 20:20

第一种:

if(window.addEventListener){  
  1.         alert("not ie");  
  2.     }else if(window.attachEvent){  
  3.         alert("is ie");  
  4.     }else 
  5.         alert("这种情况发生在不支持DHTML的老版本浏览器(现在一般都支持)" 
  6.      

第二种:

if(document.all){  
  1.     alert("IE6");  
  2.     }else 
  3.     alert("not ie");  
  4.      

第三种:

var navigatorName "Microsoft Internet Explorer" 
  1.    var isIE false 
  2.    ifnavigator.appName == navigatorName ){  
  3.     isIE true 
  4.         alert("ie" 
  5.    }else 
  6.     alert("not ie" 
  7.     

第四种:

if(!+[1,])alert("这是ie浏览器");   
  1.    else alert("这不是ie浏览器");

第五种:
function isIE() { //ie?    if (!!window.ActiveXObject || "ActiveXObject" in window)        return true;    else        return false;}if(isIE()){    alert(isIE())}else{    alert(isIE())}

个人意见第五种最好用
原创粉丝点击