0

I got a web page which has problem with compatible view mode in IE. I'm going to display an alert to users which their browsers are in compatible view in order to fix it.

My question is: Is there any way to get compatible view status( is on or off) by java script?

Super Hornet
  • 2,839
  • 5
  • 27
  • 55
  • possible duplicate of [Differentiate IE7 browser and browser in IE7 compatibility mode](http://stackoverflow.com/questions/10213639/differentiate-ie7-browser-and-browser-in-ie7-compatibility-mode) – Trevor Dixon Sep 17 '13 at 05:52

2 Answers2

1
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" />

this disables compatibility view

Alex Art.
  • 8,711
  • 3
  • 29
  • 47
1

The document.compatMode can be used to check for compatibility mode and apparently works cross-browsers (verified with IE, Chrome, Firefox):

E.g., Standard mode:

<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title></title>
<script>
window.onload = function() {
    var navigator = window.navigator;
    info.firstChild.data =
        "\n navigator.userAgent: " + navigator.userAgent +
        "\n document.compatMode: " + document.compatMode;
}
</script>
</head>
<body>
<pre id="info">&nbsp;</pre>
</body>

Output:

 navigator.userAgent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0)
 document.compatMode: CSS1Compat

Compatibility mode:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">
<head>
<title></title>
<script>
window.onload = function() {
    var navigator = window.navigator;
    info.firstChild.data =
        "\n navigator.userAgent: " + navigator.userAgent +
        "\n document.compatMode: " + document.compatMode;
}
</script>
</head>
<body>
<pre id="info">&nbsp;</pre>
</body>

Output:

 navigator.userAgent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0)
 document.compatMode: BackCompat
noseratio
  • 59,932
  • 34
  • 208
  • 486