当网站在本地 intranet 上提供服务时,Internet Explorer 将(默认情况下)切换到 IE7 兼容模式。
您可以通过在页面中包含X-UA-Compatible 响应标头来禁用此“IE7 在内网兼容模式”:
HTTP/1.1 200 OK
X-UA-Compatible: IE=8
您还可以通过在文档的HEAD> 中包含meta http-equiv 元素,将http 响应头的等效 添加到您的页面。例如:
<!DOCTYPE html>
<html>
<head>
<title>Hello world!</title>
<meta http-equiv="X-UA-Compatible" content="IE=9">
</head>
<body>
</body>
</html>
注意:如果您确实包含标题
| Header | Value |
|------------------|---------|
| X-UA-Compatible | IE=10 |
在您的 html 文档中,您必须在 HEAD 中将其添加到足够高的位置,然后才会发生锁定文档模式的其他事情 - 并且您被锁定到 IE7。
错误示例 1
<!DOCTYPE html>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<html lang="en">
<head>
meta 元素属于head 元素内
错误示例 2
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello, world!</title>
<link rel="stylesheet" type="text/css" media="all" href="main-73c2257f2d.css" />
<meta http-equiv="X-UA-Compatible" content="IE=8">
X-UA-Compatible 元素必须首先出现在head 中;除了title 和其他meta 元素。
X-UA-Compatible 标头不区分大小写;但是,它必须出现在网页的标题(HEAD 部分)中,位于除标题元素和其他元元素之外的所有其他元素之前。
错误示例 3
<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=10">
条件句将浏览器锁定到 IE7 模式。删除它们。
正确
<!doctype html>
<head>
<title>Hello, world!</title>
<meta http-equiv="X-UA-Compatible" content="IE=10">