5

I'd like to check if IE11 compatibility view is enabled for the current domain. Setting compatibility view is through: Tools > Compatibility View Settings.

I know this has been asked by a few a couple of years ago but looks like the answers doesn't work anymore due to recent update on IE11.

Does anyone know an alternative way to do this?

Byron
  • 51
  • 1
  • 3
  • Possible duplicate of [How to detect IE11?](https://stackoverflow.com/questions/17907445/how-to-detect-ie11) – Obsidian Age Oct 17 '17 at 01:41
  • Not quite the same. This is how to check IE 11 for Compatibility Mode. The above link is for checking just IE 11 version. – Jimmy Long Oct 17 '17 at 03:02
  • seems like you just need to look for `compatible` at the start of the userAgent – Jaromanda X Oct 17 '17 at 03:09
  • 2
    IE 11 Compatibility Mode is an oxymoron – zer00ne Oct 17 '17 at 05:35
  • @JaromandaX IE11 has been updated and doesn't contain the string compatible anymore – Byron Oct 18 '17 at 03:31
  • you say that, but I'm sure I've got the latest IE11 (in windows 10) and when I add a site to `compatibility view`, the userAgent definitely still has `compatible` in it – Jaromanda X Oct 18 '17 at 03:35
  • @JaromandaX I'm testing using browser stack and I don't get it on win10 or win7. The only way I could get it is using IE10. Also tested win10 machine and no luck. How tdo you set compatibility view? Is it under Tools > Compatibility View Settings? – Byron Oct 18 '17 at 03:55
  • yes that's where it is - normal userAgent is `Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko` ... post compatibility view it's `Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0;)` (removed the .NET stuff for clarity) - About IE11: `Version: 11.674.15063.0`, `Update Versions: 11.0.47` – Jaromanda X Oct 18 '17 at 03:57

2 Answers2

1

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

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

  • Loading a page with a <meta http-equiv tag changes the value

  • Adding a site to compatibility mode in "Tools -> Compatibility View settings" changes the value to 7.

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

Examples

For example if I load this page in IE11 I get documentMode of 11.

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

This page loaded in IE11 sets documentMode to 9.

<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=9"/>
</head>
<body>
<p>Hello World!<p>
</body>
</html>
david25272
  • 976
  • 6
  • 12
  • I'd like to detect if compatibility view is enabled not compatibility mode under dev tools which I think you're referring to emulation tab. On IE11 setting compatibility view is through -- Tools > Compatibility View Settings – Byron Oct 18 '17 at 03:25
0

If you just wanting to check if you are being run in compatibility mode you can use this script.

// Create new ieUserAgent object

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-

/** * Check if client is IE and in compatibility view * * @returns {boolean} */

function isIECompatibilityMode() {

    var ua = navigator.userAgent;

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

        return false;

    }

    return (ua.indexOf("compatible") != -1); }
User
  • 31
  • 5
  • 1
    Thanks Janaki but this is same as the old solution, The IE11 update I mentioned above removed the string "MSIE" regardless if you're in compatibility view or not so this wouldn't work. – Byron Oct 17 '17 at 02:14