zoukankan      html  css  js  c++  java
  • javascript判断浏览器类型

    js用来区别IE与其他浏览器及IE6-8之间的方法。


    1、document.all
    2、!!window.ActiveXObject; 。!!的作用是把一个其他类型的变量转成的bool类型


    使用方法如下:


    if (document.all){
      alert(”IE浏览器”);
    }else{
    alert(”非IE浏览器”);
    }


    if (!!window.ActiveXObject){
      alert(”IE浏览器”);
    }else{
      alert(”非IE浏览器”);
    }


    下面是区别IE6、IE7、IE8之间的方法:


    所以obj.setAttribute('onclick',document.all ? eval(function(){show()}) : 'javascript:show()'); 要改为:
    一:obj.setAttribute('onclick',document.all && !document.documentMode ? eval(function(){show()}) : 'javascript:show()');
    二:如果不想像上面那样改,也可以将ie8声明为ie7.http://www.huiyi8.com/tishiyin/


    在head标签上加上<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />


    标签: Javascript 调试插件提示音

    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″);
      }
    }
  • 相关阅读:
    P2045 方格取数加强版
    P2774 方格取数问题
    日记——OI历程
    6.30考试
    6.29考试
    数论...
    6.28数论测试
    洛谷P3802 小魔女帕琪
    hosts
    博客设置
  • 原文地址:https://www.cnblogs.com/xkzy/p/3865765.html
Copyright © 2011-2022 走看看