1

How can I check using Javascript is compatibility view is on?

Doesn't matter which version of IE it is, I just need to know whether or not compatibility view is switched on.

Andrey Belykh
  • 2,578
  • 4
  • 32
  • 46
Simon R
  • 3,732
  • 4
  • 31
  • 39
  • possible duplicate: http://stackoverflow.com/questions/1328963/detect-ie8-compatibility-mode – Andrei Apr 07 '11 at 12:32
  • yeah, but none of these answers explain how you can attain the compatability mode button (that appears next to the bookmark star on the right hand side of the URL field). They just explain how to detect it. If the button can be enabled then the user will easily be able to click the button to toggle compat mode without needing to go into the menu. – djangofan Dec 03 '12 at 17:37
  • See this question http://stackoverflow.com/questions/1328963/detect-ie8-compatibility-mode – Jim Blackler Apr 07 '11 at 12:33
  • As above, This will only tell me what engine is being used. If the webpage is using compatability mode, the version of IE changes on the useragent so there is no way to tell if there a difference between the current version (with compatability mode off) and the engine. – Simon R Apr 07 '11 at 13:42

2 Answers2

1

Determining Document Compatibility Mode

engine = null;
    if (window.navigator.appName == "Microsoft Internet Explorer")
    {
       // This is an IE browser. What mode is the engine in?
       if (document.documentMode) // IE8 or later
          engine = document.documentMode;
       else // IE 5-7
       {
          engine = 5; // Assume quirks mode unless proven otherwise
          if (document.compatMode)
          {
             if (document.compatMode == "CSS1Compat")
                engine = 7; // standards mode
          }
          // There is no test for IE6 standards mode because that mode  
          // was replaced by IE7 standards mode; there is no emulation.
       }
       // the engine variable now contains the document compatibility mode.
    }
Andrei
  • 4,237
  • 3
  • 25
  • 31
  • This will only tell me what engine is being used. If the webpage is using compatability mode, the version of IE changes on the useragent so there is no way to tell if there a difference between the current version (with compatability mode off) and the engine. – Simon R Apr 07 '11 at 13:41
  • This method appears to be pretty good but the code (above) needs to be enhanced for IE9 and IE10. There is some more important info here: http://msdn.microsoft.com/en-us/library/cc288325%28VS.85%29.aspx – djangofan Dec 03 '12 at 17:39
0

Stumbled upon this blog post a while ago. Maybe this is what you're looking for: http://blog.strictly-software.com/2009/03/detecting-ie-8-compatibility-modes-with.html

stlvc
  • 833
  • 5
  • 16