简体   繁体   English

IE检测不起作用

[英]IE detection not working

I wanted to detect IE8 and 9 via JavaScript. 我想通过JavaScript检测IE8和9。 All of them return as 7. I tried JQuery-1.8.2, but same results. 它们全部返回7。我尝试了JQuery-1.8.2,但结果相同。

It returns "Compatible" version or something. 它返回“兼容”版本或其他内容。 If both IE8 and 9 versions use their IE version as 7, why they behave differently? 如果IE8和9版本都使用IE版本7,为什么它们的行为有所不同? Why MS labels it as 8 and 9 and send some other version details on the IP header?. 为什么MS将其分别标记为8和9,并在IP标头上发送其他一些版本详细信息? Is this the expected behavior of IE? 这是IE的预期行为吗?

I tried this too. 我也尝试过 http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx

Can anyone give an explanation about this. 任何人都可以对此进行解释。 Thanks. 谢谢。

You can find a solution Detect IE version (prior to v9) in JavaScript 您可以在JavaScript中找到检测IE版本(v9之前的版本)的解决方案

See: 看到:

<!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>

and then: 接着:

(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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM