[Web開發] 快速修復網頁在IE8 下的顯示兼容問題

IE8在默認情況下是使用全新的標準模式(Standard Mode)顯示引擎來顯示網頁。 如果網頁代碼還沒有標準化, 在IE8下可能會顯示不正常。 重寫網頁代碼使之標準化的工作量很大,需要長時間慢慢修復。 一個簡單快捷的方法就是讓IE8繼續IE7的顯示引擎來顯示你的網站,我們稱這個舊的顯示引擎爲兼容視圖(Compatibility View) 。

在網頁裏面加入這行代碼就可以使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 服務器, 可以配置 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>

或者通過配置工具來改:

IIS IE8 兼容

如果用的是Apache 服務器,可以配置 httpd.conf 文件:

LoadModule headers_module modules/mod_headers.so

Header set X-UA-Compatible 「IE=EmulateIE7」

以上是使所有的網頁都使用兼容視圖。如果只想讓個別目錄下的文件用兼容視圖,在<location>下設置:

<Location /myfolder> Header set X-UA-Compatible 「IE=EmulateIE7」</Location>