2011-04-07 54 views
1

如何使用Javascript檢查兼容性視圖?Javascript檢查兼容性視圖是否在

無論它是哪個版本的IE,我只需要知道是否打開兼容性視圖。

+0

可能重複:http://stackoverflow.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://stackoverflow.com/questions/1328963/detect-ie8-compatibility-mode – 2011-04-07 12:33:33

回答

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