您的位置:首页 > 其它

IE 定义文档兼容性

2013-09-14 11:26 232 查看
1. 指定文档兼容性模式

若要为网页指定文档模式,请使用 meta 元素,以在网页中包含 X-UA-Compatible  http-equiv 标头

<html>
<head>
<!-- Mimic Internet Explorer 7 -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" >
<title>My Web Page</title>
</head>
<body>
<p>Content goes here.</p>
</body>
</html>


2. 配置 Web 服务器以指定默认兼容性模式

<?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>


如果使用 Web 服务器指定了默认的文档兼容性模式,则可通过在特定的网页中指定不同的文档兼容性模式来覆盖默认设置。 在网页中指定的模式优先于由 Web 服务器指定的模式。

有关如何指定自定义标头的信息

3. 确定文档兼容性模式

engine = null;
if (window.navigator.appName == "Microsoft Internet Explorer")
{
// This is an IE browser. What mode is the engine in?
if (document.documentMode) // IE8
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
}
}
// the engine variable now contains the document compatibility mode.
}


4. content 的属性值

<meta http-equiv="X-UA-Compatible" content="IE=4">   <!-- IE5 mode -->
<meta http-equiv="X-UA-Compatible" content="IE=7.5" > <!-- IE7 mode -->
<meta http-equiv="X-UA-Compatible" content="IE=100" > <!-- IE8 mode -->
<meta http-equiv="X-UA-Compatible" content="IE=a" >   <!-- IE5 mode -->


如果某个特定的 Internet Explorer 版本支持多个请求的兼容性模式,则该版本将使用标头的 content 属性中列出的可用的最高级别模式。 可以利用这一原理来排除特定的兼容性模式,但不建议这样做。 例如,下面的标头排除了 IE7 模式

<meta http-equiv="X-UA-Compatible" content="IE=5; IE=8" >
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  IE 兼容模式