Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if IE11 is in compatibility view using JS

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?

like image 855
Byron Avatar asked Nov 07 '22 15:11

Byron


1 Answers

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>
like image 115
david25272 Avatar answered Nov 14 '22 23:11

david25272