問題描述
我正在為在所有內部網站上強制兼容性模式的客户端工作。我想知道是否有一個標籤,我可以放入我的 HTML,強制兼容模式關閉。
最佳解決方案
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>My Web Page</title>
</head>
<body>
<p>Content goes here.</p>
</body>
</html>
從鏈接的 MSDN 頁面:
Edge mode tells Windows Internet Explorer to display content in the highest mode available, which actually breaks the 「lock-in」 paradigm. With Internet Explorer 8, this is equivalent to IE8 mode. If a (hypothetical) future release of Internet Explorer supported a higher compatibility mode, pages set to Edge mode would appear in the highest mode supported by that version; however, those same pages would still appear in IE8 mode when viewed with Internet Explorer 8.
但是,在生產中不鼓勵使用”edge” 模式:
It is recommended that Web developers restrict their use of Edge mode to test pages and other non-production uses because of the possible unexpected results of rendering page content in future versions of Windows Internet Explorer.
我真的不完全明白為什麼。但是根據這一點,目前最好的方法是使用 IE=8 。
次佳解決方案
經過多少小時的故障排除這些東西… 這裏有一些快速的亮點,幫助我們從 X-UA-Compatible 文檔:http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx#ctl00_contentContainer_ctl16
使用<meta http-equiv="X-UA-Compatible" content=" _______ " />
-
標準用户代理模式 (non-emulate) 忽略了您的頁面中的
<!DOCTYPE>指令,並根據該版本的 IE 支持的標準進行渲染 (例如,IE=8將更好地遵守表邊框間距和一些偽選擇器比IE=7) 。 -
而 Emulate 模式告訴 IE 遵循您頁面中的任何
<!DOCTYPE>指令,根據您選擇的版本渲染標準模式和基於IE=5的奇怪模式 -
content屬性的可能值為:content="IE=5"content="IE=7"content="IE=EmulateIE7"content="IE=8"content="IE=EmulateIE8"content="IE=9"content="IE=EmulateIE9"content="IE=edge"content="IE=edge"
第三種解決方案
如果您正在使用 Intranet Zone 中的一個頁面,您可能會發現 IE9 無論您做了什麼,都將進入 IE7 兼容模式。
這是因為 IE 兼容性設置中的設置表示所有 Intranet 站點都應以兼容模式運行。您可以通過組策略 (或者在 IE 中簡單的解除它) 來取消選擇,也可以設置以下內容:
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
這樣做 (如其他答案中所述),但可能最初不會顯示:它需要在聲明樣式表之前。如果不這樣做,那就被忽略了。
第四種方案
我相信這會做的訣竅:
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
第五種方案
元標記解決方案不適用於我們,但在響應頭中設置它:
header('X-UA-Compatible: IE=edge,chrome=1');
第六種方案
如本 answer 中提到的相關問題,可以在 Web.Config 文件中設置”edge” 模式。這將使其適用於從應用程序返回的所有 HTML,而無需將其插入到單獨的頁面中:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-UA-Compatible" value="IE=edge" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
也可以通過 modifying the “HTTP Response Headers” using IIS Manager 為 IIS 服務器,整個網站或特定應用程序完成同樣的步驟。
第七種方案
基於我最近的經驗,還有幾個關於這個話題的筆記。我工作的大學問題筆記本電腦與 IE 8 設置為所有 Intranet 網站的兼容性模式。我嘗試添加元標記,以禁用此模式為我的網站提供的網頁,但 IE 始終忽略此標記。正如蘭斯在他的帖子中所説,添加一個響應標題來解決這個問題。這是我如何根據 HTML5 樣板方法設置頭文件:
<IfModule mod_headers.c>
Header set X-UA-Compatible "IE=edge,chrome=1"
# mod_headers can't match by content-type, but we don't want to send this header on *everything*...
<FilesMatch ".(appcache|crx|css|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svg|svgz|ttf|vcf|webm|webp|woff|xml|xpi)$">
Header unset X-UA-Compatible
</FilesMatch>
</IfModule>
為了實際發送此標題,您必須確保在 Apache 中已啓用 mod_headers 。如果你想確保你打開這個 mod,把它放在一個可以運行 php 的頁面中:
<pre>
<?php
print_r(apache_get_modules());
?>
</pre>
第八種方案
IE8 默認為 intRAnet 的 intERnet 和 quirks 模式的標準模式。如果您將 doctype 設置為 xhtml 過渡,則會忽略 HTML 元標記。解決方案是在代碼中添加一個 HTTP 頭。這對我們有用。現在我們的內部網站強制 IE8 以標準模式呈現應用程序。
添加到基頁類 (ASP.net C#) 的 PageInit:Response.AddHeader(“X-UA-Compatible”,”IE=EmulateIE8”);
參考:http://ilia.ws/archives/196-IE8-X-UA-Compatible-Rant.html
第九種方案
這是因為 IE 兼容性設置中的設置表示所有 Intranet 站點都應以兼容模式運行。您可以通過組策略 (或者在 IE 中簡單的解除它) 來取消選擇,也可以設置以下內容:
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
顯然,不可能將兼容性視圖設置更改為組策略,但它可能在註冊表中更改,這個元標記對我來説可以正常工作,我必須使所需的屬性作為 html 表單的一部分,它的工作在 chrome 和 firefox 但不是 IE 。
以下是瀏覽器支持每個 html 5 元素的一個很好的視覺效果。
請注意 Google Chrome 的一個共同特徵,它支持所有內容。希望這是有幫助的
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。