【问题标题】:How to detect if a user is running IE 6?如何检测用户是否正在运行 IE 6?
【发布时间】:2009-05-28 02:22:17
【问题描述】:

我需要能够判断页面是否正在 IE 6 中查看。如何在 javascript 中执行此操作而忽略 7、8 或其他浏览器等版本?

【问题讨论】:

    标签: javascript html internet-explorer-6


    【解决方案1】:

    直接来自horse's mouth(并且一个谷歌搜索):

    function getInternetExplorerVersion()
    // Returns the version of Internet Explorer or a -1
    // (indicating the use of another browser).
    {
      var rv = -1; // Return value assumes failure.
      if (navigator.appName == 'Microsoft Internet Explorer')
      {
        var ua = navigator.userAgent;
        var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
          rv = parseFloat( RegExp.$1 );
      }
      return rv;
    }
    

    【讨论】:

      【解决方案2】:

      你可以使用conditional comments

      【讨论】:

      • +1:我实际上将它与 mkoryak 的答案结合使用。
      • 这是一种更好的方法——因为它在使用 IE6 引擎的其他浏览器上给出了“正确”的结果,并且不受用户代理欺骗的影响。更好的是可能使用功能 AKA 对象检测而不是用户代理检测 - quirksmode.org/js/support.html
      • 你知道,我提供的链接包含所有这些信息,关于条件 cmets 和特征检测,甚至还有一些 hacks
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      • 1970-01-01
      相关资源
      最近更新 更多