IE8 採用 W3C 國際通用標準,同時為了兼顧依舊標準開發的網站,特別提供了「兼容性視圖」。當 IE8 偵測到某個網站不相容時,位址列右側會浮現兼容性視圖按鈕,點一下,多數頁面的顯示就恢復正常。
而且不必每次重複操作:按下按鈕後,該網站會自動進入兼容性清單,下次造訪時 IE8 會主動啟用兼容性視圖。
想一勞永逸也很簡單——點右側「工具」按鈕,選擇「兼容性視圖設定」,勾選「在兼容性視圖中顯示所有網站」,從此告別相容性造成的跑版。
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
完整範例:
<html> <head> <!-- Use IE7 mode --> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> <title>My Web Page</title> </head> <body> <p>Content goes here.</p> </body> </html>
不想每頁都寫,也可以在 IIS 站台屬性的「HTTP 標頭」頁籤新增自訂標頭:名稱 X-UA-Compatible、值 IE=EmulateIE7,套用即可。
IIS 使用者可改寫 web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<clear/>
<add name="X-UA-Compatible" value="IE=EmulateIE7"/>
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
Apache 則改 httpd.conf:
LoadModule headers_module modules/mod_headers.so Header set X-UA-Compatible "IE=EmulateIE7"
若只想讓某個目錄下的檔案走兼容性視圖,把最後一行放到該目錄的設定區塊或 .htaccess 中即可。