How to check if IE11 is in JS Compatibility View

I want to check if IE11 compatibility mapping is enabled for the current domain. The compatibility view is configured through: Tools> Compatibility View Settings.

I know this was asked a few years ago, but it looks like the answers no longer work due to the latest update in IE11.

Does anyone know an alternative way to do this?

+4
source share
2 answers

In versions of IE 8-11 you can use document.documentMode. Valid values ​​are 5, 7 (compatibility mode), 8, 9, 10, and 11 (Edge).

  • Setting the compatibility mode in the console directly changes the value.

  • <meta http-equiv

  • " → settings " 7.

https://msdn.microsoft.com/en-us/library/jj676915(v=vs.85).aspx

< >

, IE11, documentMode 11.

<!doctype HTML>
<body>
<p>Hello World!<p>
</body>

IE11 documentMode 9.

<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=9"/>
</head>
<body>
<p>Hello World!<p>
</body>
</html>
+1

, , script.

// ieUserAgent

var ieUserAgent = {

init: function () {

// Get the user agent string

var ua = navigator.userAgent;

this.compatibilityMode = false;

   // alert (ua);

    if(ua.indexOf("MSIE") == -1){

        this.version = 0;

        return 0;

    }

    if(ua.indexOf("compatible") == -1){

        this.compatibilityMode = false;

        return 0;

    }else{

        this.compatibilityMode = true;

        return 0;

    }

}
};

// Initialize the ieUserAgent object
ieUserAgent.init();

-OR -

/**  * , IE  *  * @returns {boolean}  */

function isIECompatibilityMode() {

    var ua = navigator.userAgent;

    if (ua.indexOf("MSIE") == -1) {

        return false;

    }

    return (ua.indexOf("compatible") != -1); }
0

Source: https://habr.com/ru/post/1687597/


All Articles