【问题标题】:IE detection not workingIE 检测不起作用
【发布时间】:2013-10-21 06:58:23
【问题描述】:

我想通过 JavaScript 检测 IE8 和 9。它们都返回为 7。 我尝试了 JQuery-1.8.2,但结果相同。

它返回“兼容”版本或其他东西。 如果 IE8 和 9 版本都将其 IE 版本用作 7,为什么它们的行为不同? 为什么 MS 将其标记为 8 和 9 并在 IP 标头上发送一些其他版本详细信息?这是 IE 的预期行为吗?

我也试过这个。 http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx

谁能解释一下。 谢谢。

【问题讨论】:

  • 希望能对我在下面发布的答案提供意见
  • @leonid:当然。有一个糟糕的一天。我只是暂时忽略了 IE 检查作为临时解决方案。我去看看。

标签: javascript jquery internet-explorer-8 internet-explorer-9


【解决方案1】:

您可以找到解决方案Detect IE version (prior to v9) in JavaScript

见:

<!doctype html>
<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->
<head>

然后:

(function ($) {
    "use strict";

    // Detecting IE
    var oldIE;
    if ($('html').is('.ie6, .ie7, .ie8')) {
        oldIE = true;
    }

    if (oldIE) {
        // Here's your JS for IE..
    } else {
        // ..And here's the full-fat code for everyone else
    }

}(jQuery));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多