How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?

前端 未结 25 2639
谎友^
谎友^ 2020-11-22 06:19

How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?

I tried this, but

25条回答
  •  礼貌的吻别
    2020-11-22 06:45

    I just wanted to add my version of IE detection. It's based on a snippet found at http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/ and exteded to also support ie10 and ie11. It detects IE 5 to 11.

    All you need to do is add it somewhere and then you can always check with a simple condition. The global var isIE will be undefined if it's not an IE, or otherwise it will be the version number. So you can easily add things like if (isIE && isIE < 10) or alike.

    var isIe = (function(){
        if (!(window.ActiveXObject) && "ActiveXObject" in window) { return 11; /* IE11 */ }
        if (Function('/*@cc_on return /^10/.test(@_jscript_version) @*/')()) { return 10; /* IE10  */ }
        var undef,
            v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i');
        while (
            div.innerHTML = '',
                all[0]
            );
        return v > 4 ? v : undef;
    }());
    

提交回复
热议问题