Javascript检查兼容性视图是否在

问题描述:

如何使用Javascript检查兼容性视图?Javascript检查兼容性视图是否在

无论它是哪个版本的IE,我只需要知道是否打开兼容性视图。

+0

可能重复:http://*.com/questions/1328963/detect-ie8-compatibility-mode – Andrei 2011-04-07 12:32:12

+0

是的,但没有这些答案解释了如何获得兼容性模式按钮(它出现在URL字段右侧的书签星标旁边)。他们只是解释如何检测它。如果可以启用该按钮,则用户将能够轻松地点击该按钮来切换共享模式而不需要进入菜单。 – djangofan 2012-12-03 17:37:28

+0

看到这个问题http://*.com/questions/1328963/detect-ie8-compatibility-mode – 2011-04-07 12:33:33

不久前发生在此博客文章。也许这是你在找什么:http://blog.strictly-software.com/2009/03/detecting-ie-8-compatibility-modes-with.html

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. 
    } 
+0

这只会告诉我正在使用什么引擎。如果网页使用兼容性模式,则IE的版本会在useragent上发生变化,因此无法确定当前版本(关闭兼容模式)与引擎之间是否存在差异。 – 2011-04-07 13:41:23

+0

这个方法看起来很不错,但是IE9和IE10需要增强代码(以上)。这里有一些更重要的信息:http://msdn.microsoft.com/en-us/library/cc288325%28VS.85%29.aspx – djangofan 2012-12-03 17:39:20