问题描述
在微软的网站上,他们声称简单的doctype声明就足够了。但即便是这样简短的文件又回归到IE7模式:
On microsoft's site they claim that simple doctype declaration is enough. But even a document as short as this falls back to IE7 mode:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
推荐答案
Internet Explorer假设大多数网页都是早先写入目标的IE的版本并查看doctype,meta标签和HTML以确定最佳兼容模式(有时不正确)。即使使用HTML5文档类型,IE仍然会将您的网站置于兼容模式(如果它是内部网站点)。
Internet Explorer makes the assumption that most webpages were written to target earlier versions of IE and looks at the doctype, meta tags and HTML to determine the best compatibility mode (sometimes incorrectly). Even with a HTML5 doctype IE will still place your website in compatibility mode if it's an intranet site.
为了确保您的网站始终使用最新的标准模式,您可以制作确定已关闭在Compatitence
中显示Intranet网站。但是,您必须在Web服务器本地的每台计算机上执行此操作(请参阅下文)。
To ensure that your website always uses the latest standards mode you can either make sure Display intranet sites in Compatibly
is turned off. However you've have to do this on each machine local to the web server (Instructions are below).
或者更好的是,您可以使用X-UA兼容标题从服务器关闭它。重要的是要注意使用元标记的不起作用!。
Alternatively and better yet you can use the X-UA-Compatible header to turn this off from the server. It's important to note that using the meta tag will not work!.
<!-- Doesn't always work! -->
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
在整个MSDN中,提到使用主机头或元标记应该覆盖甚至内联网站点
。文章说明如下。
Throughout MSDN it's mentioned that using a host header or a meta tag should override even intranet sites
. The article Understanding compatibility modes in internet explorer 8 says the following.
但是,实际上这不起作用,使用主机头是唯一有效的选项。本文的评论部分还显示了这个确切问题的大量示例。
However, in practice this will not work, using a host header is the only option that works. The comments section of the article also shows numerous examples of this exact issue.
使用Meta标签还有其他几个问题,例如忽略标签,如果它不直接位于< head>
标记或前面有太多数据(4k)。它还可能触发在某些IE版本中重新分析文档,这将减慢渲染速度。您可以在MSDN文章最佳实践:按顺序获取HEAD。
Using a Meta tag also has several other issues such as ignoring the tag if it's not directly under the <head>
tag or if there is too much data before it (4k). It may also trigger the document to be reparsed in some versions of IE which will slow down rendering. You can read more about these issues at the MSDN article Best Practice: Get your HEAD in order.
添加X-UA兼容标题
如果您使用.net和IIS,可以将其添加到web.config,您也可以以编程方式:
If you are using .net and IIS you can add this to the web.config, you could also do this programmatically:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-UA-Compatible" value="IE=edge" />
</customHeaders>
</httpProtocol>
</system.webServer>
如果您没有使用IIS,那么很容易用任何语言进行操作,例如这里有怎么做在php中:
If you're not using IIS it's easy to do in any language for example here's how to do it in php:
header('X-UA-Compatible: IE=edge');
只要X-UA-Compatible标头与html5 doctype一起出现,网站将始终运行在最新的标准模式下。
As long as the X-UA-Compatible header is present with the html5 doctype a site will always run in the latest standards mode.
关闭兼容性视图
关闭兼容性视图可能仍然有用。为此,取消选中在兼容性视图设置中显示兼容性视图中的所有Intranet站点
。
你可以通过点击<$ c $来提高它c> alt 获取菜单
You can bring this up by hitting alt
to get the menu
修改
此答案也适用于IE9
EditThis answer also pertains to IE9
这篇关于IE10以IE7模式呈现。如何强制标准模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!