2015-03-13 63 views

回答

0

您必須測試只存在於IE8或更高版本中的document.documentMode值。如果在IE8標準模式下顯示頁面,則引擎值爲8,但如果頁面以IE7兼容模式(在IE8瀏覽器上)顯示,則值將爲7.

此代碼片段是從Microsoft MSDN中提取的,並且我認爲這是自我解釋。

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

但是,您需要知道以前至尊版本的IE瀏覽器正在顯示頁面。所以如果它是8並且返回的值是7,那麼以兼容模式顯示。