Identify IE9/IE10 using jQuery

后端 未结 5 1925
庸人自扰
庸人自扰 2020-12-18 09:22

I have a jQuery code which is working fine for Chrome/Mozilla but not IE.

if ($(\"html\").hasClass(\"ie\")) {
    $(function(){
        $(\'.green-column, .         


        
5条回答
  •  不知归路
    2020-12-18 10:11

    The only reliable way to detect the currently active IE version (possibly emulated) is to combine conditional compilation and a document.documentMode check.

    Conditional compilation is optional, but it allows you to never run the IE-detection script for non-IE browsers.

    For example:

    if (/*@cc_on !@*/false && (
           document.documentMode === 9 || document.documentMode === 10)
       ) {
        // IE 9 or 10 (not 8 or 11!)
        document.documentElement.className += ' ie9 ie10';
    }
    

    The previous code is not safe against minifiers. If you're going to minify your code, put the conditional compilation stuff in a string, and eval it:

    if (eval('/*@cc_on !@*/false') && ( ... )) { ... }
    

提交回复
热议问题