3

I use javascript script to align certain elements using offsets. Offsets are calculated depending on browser type because they behave differently. In IE9, getting child elements in the DOM or calculating certain offsets, the behavior is different if IE9 is in IE9 browser mode or IE9 compatible view browser mode.

How do I detect if the Browser mode is in "Internet Explorer 9 compatibility View"? This mode is set by the user in developer tools (F12) Browser Mode menu option.

Tony_Henrich
  • 42,411
  • 75
  • 239
  • 374
  • No. There are two more options for IE7 and IE8. Total of 4. – Tony_Henrich Nov 15 '12 at 22:57
  • possible duplicate of [JavaScript: Can I detect IE9 if it's in IE7 or IE8 compatibility mode?](http://stackoverflow.com/questions/5825385/javascript-can-i-detect-ie9-if-its-in-ie7-or-ie8-compatibility-mode) – Andreas Louv Nov 15 '12 at 23:06

3 Answers3

1

Pretty sure, I'm running Linux and my virtual image just broke:

if (document.all && document.documentMode === 8 && !document.addEventListener) {
    // IE9/IE10 in compatibility mode as IE8
}

On UA:

https://stackoverflow.com/a/12183662/887539

Community
  • 1
  • 1
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
0

I can't remember where I got this code, but basically IE8 and up have a property on the document called "documentMode". If that exists, but you're seeing IE7 as the browser, you can safely assume that you are in compatibility mode.

documentMode explaination

Stephen
  • 5,362
  • 1
  • 22
  • 33
0

It is possible, user agent string is different for IE9 when being run in IE7 compatibility mode, so this would be one of the best ways to find the difference between different IE versions.

You can read more about this here: http://blogs.msdn.com/b/ie/archive/2010/03/23/introducing-ie9-s-user-agent-string.aspx

Gurpreet Singh
  • 20,907
  • 5
  • 44
  • 60