10

我無法禁用IE9中的IE兼容模式按鈕。如何禁用IE9中的兼容模式按鈕?

我的頭,DOCTYPE是這樣的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<!--[if lte IE 8]> 
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-en" xml:lang="en-en" class="ie8"> 
<![endif]--> 
<!--[if IE 9]> 
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-en" xml:lang="en-en" class="ie9"> 
<![endif]--> 
<!--[if (gt IE 9)|!(IE)]><!--> 
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-en" xml:lang="en-en"> 
<!--<![endif]--> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame --> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 
    <meta name="description" content="meta content here" /> 
    </head> 
    <body> 
    <!-- page content here //--> 
    </body> 
</html> 

如何禁用IE9的兼容模式按鈕?

我以爲我做了我的研究。我應用了每種類型的後備解決方案,以便在每個IE中從7到9以上顯示一切正常。

客戶端抱怨兼容模式,當它被激活時,它會弄亂佈局。有什麼辦法可以禁用那個按鈕嗎?

回答

4
+0

問題依然存在。即使我將其更改爲: ' ' – Cyrax

+0

您是否檢查控制檯中是否有類似的消息?您使用條件註釋來聲明HTML標記會爲我提升標誌。 –

+2

我使用Paul Irish提出的解決方案來處理X瀏覽器的兼容性問題。只有針對particula瀏覽器的標籤纔會被解析。沒有消息在控制檯中彈出。 – Cyrax

18
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 

鉻幀已經停止由谷歌如2014年1月的,因此鉻= 1個部分是不需要

<meta http-equiv="X-UA-Compatible" content="IE=edge"> 

的 「邊緣」 的力的標準模式 (或最新的渲染引擎)在IE瀏覽器和「鉻」爲Chrome框架。

更多信息可在這裏:

+4

我終於得到了這個工作(雖然我沒有包括'chrome'位),當我將這個標記移動到'' – Michael

+1

'後的第一件事*時,''內的位置應該沒有關係。但是像<! - [if gte IE 8]>'這樣的條件標籤會干擾正確的meta標籤,所以請勿使用它們。導致兼容模式按鈕消失的元件(在Windows 7上的IE10中測試)爲:' – goddogsrunning

0

的問題是,在你的js代碼放到你正在使用的瀏覽器嗅探喜歡的document.all代碼, window.ActiveXObject,navigatror.userAgent,attachEvent,detachEvent等。

使用功能檢測代碼替換所有內容使用 jquery.support並且該按鈕將消失。

1

我發現它是導致按鈕出現的條件註釋。刪除這些並使用功能檢測來代替添加我的html類已經解決了這個問題。沒有任何修補與X-UA-Compatible東西會刪除按鈕。我用這一套has.js

檢測:

if (has("css-border-radius") && !has("input-attr-placeholder")) { 
    html.className += ' ie9'; 
} 

if (!has("css-border-radius") && !has("input-attr-placeholder")) { 
    html.className += ' lt-ie9'; 
} 

if (!has("css-box-sizing")) { 
    html.className += ' ie7'; 
} 
5

我是用條件註釋頁面的頂部嵌入基於版本的ie類。(例如:)

<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]--> 

其結果是,即使我設置X-UA-Compatible元標記,則相容性模式按鈕仍被在IE中所示。

要解決這個問題,我必須將條件註釋移動到頁面底部,並使用JS應用ie類。查看我的網站時,IE中不再顯示兼容性按鈕。

<html lang="en"> 
    <head> 
    <meta http-equiv="X-UA-Compatible" content="IE=8; IE=9; IE=10; IE=EDGE; chrome=1"> 
    <head> 
    <body> 
    <!-- ..Other content... --> 
    <script type="text/javascript"> 
    window.flagAsIE = function(version) { 
    var cls = document.body.parentElement.getAttribute('class'); 
    document.body.parentElement.setAttribute('class', "ie ie" + version + " " + cls); 
    }; 
    </script> 

    <!--[if lt IE 7 ]><script type='text/javascript'>flagAsIE('6');</script><![endif]--> 
    <!--[if IE 7 ]><script type='text/javascript'>flagAsIE('7');</script><![endif]--> 
</body> 
</html>