windows IE10 以 IE7 模式呈现。如何强制标准模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13284083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IE10 renders in IE7 mode. How to force Standards mode?
提问by firedev
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 声明就足够了。但即使是这么短的文档也会退回到 IE7 模式:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
回答by Daniel Little
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.
Internet Explorer 假设大多数网页都是针对早期版本的 IE 编写的,并查看文档类型、元标记和 HTML 以确定最佳兼容模式(有时是错误的)。即使使用 HTML5 doctype,如果您的网站是 Intranet 站点,IE 仍会将您的网站置于兼容模式。
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 have to do this on each machine local to the web server (instructions are below).
为确保您的网站始终使用最新的标准模式,您可以确保Display intranet sites in Compatibly
已关闭。但是,您必须在 Web 服务器本地的每台机器上执行此操作(说明如下)。
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!
或者,更好的是,您可以使用X-UA-Compatible
标头从服务器关闭此功能。请务必注意,使用元标记将不起作用!
<!-- Doesn't always work! -->
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
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 8says the following.
在整个 MSDN 中,都提到使用主机标头或元标记甚至应该覆盖内部网站。文章在Internet Explorer 8了解兼容模式表示如下。
A large number of internal business web sites are optimized for Internet Explorer 7 so this default exception preserves that compatibility. ... Again if a Meta tag or http header is used to set a compatibility mode to the document it will override these settings.
大量内部商业网站针对 Internet Explorer 7 进行了优化,因此此默认例外保留了这种兼容性。... 同样,如果使用 Meta 标记或 http 标头为文档设置兼容模式,它将覆盖这些设置。
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.
然而,实际上这行不通,使用主机头是唯一有效的选项。文章的评论部分还显示了这个确切问题的许多示例。
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.
使用 Meta 标签还有其他几个问题,例如如果标签不在<head>
标签下,或者在它之前有太多数据 (4k) ,则忽略该标签。它也可能会触发文档在某些版本的 IE 中重新解析,这会减慢渲染速度。您可以在 MSDN 文章Best Practice: Get your HEAD in order 中阅读有关这些问题的更多信息。
Adding the X-UA-Compatible header
添加 X-UA-Compatible 标头
If you are using .NET and IIS you can add this to the web.config
, you could also do this programmatically:
如果您正在使用 .NET 和 IIS,您可以将其添加到web.config
,您也可以以编程方式执行此操作:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-UA-Compatible" value="IE=edge" />
</customHeaders>
</httpProtocol>
</system.webServer>
If you're not using IIS it's easy to do in any language. For example, here's how to do it in PHP:
如果您不使用 IIS,则使用任何语言都可以轻松完成。例如,这里是如何在 PHP 中执行此操作:
header('X-UA-Compatible: IE=edge');
As long as the X-UA-Compatible
header is present with the HTML5 doctype, a site will always run in the latest standards mode.
只要X-UA-Compatible
标题与 HTML5 文档类型一起存在,站点将始终以最新的标准模式运行。
Turning off Compatibility View
It may still be useful to turn off Compatibility View. To do so untick Display all intranet sites in compatibility view
in the Compatibility View Settings.
关闭兼容性视图 关闭兼容性视图
可能仍然有用。为此,请Display all intranet sites in compatibility view
在兼容性视图设置中取消勾选。
You can bring this up by hitting Altto get the menu.
您可以通过点击Alt获取菜单来提出此问题。
EditThis answer also pertains to IE9.
编辑此答案也适用于 IE9。
回答by JGilmartin
This works for me..
这对我有用..
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
回答by Jeow Li Huan
Try adding the following tag to the head
尝试将以下标签添加到头部
<meta http-equiv="X-UA-Compatible" content="IE=11,IE=10,IE=9,IE=8" />
回答by o.v.
The meta tag doesn't do anything for intranet sites and my issue was IE10 rendering in IE10 compatibility mode. What tackled the issue for me was taking @Jeow's answerfurther and using that value in an http header by adding the following to web.config
under IIS:
元标记对 Intranet 站点没有任何作用,我的问题是 IE10 兼容模式下的 IE10 呈现。对我来说解决这个问题的是进一步采取@Jeow 的回答,并通过web.config
在 IIS 下添加以下内容在 http 标头中使用该值:
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<!-- <add name="X-UA-Compatible" value="IE=edge" /> not good enough -->
<add name="X-UA-Compatible" value="IE=11,IE=10,IE=9,IE=8" />
</customHeaders>
</httpProtocol>
</system.webServer>
For IE purposes, intranet sites include public-facing sites that are not routed to externally - for example a Stackoverflow employee working from the office would probably see stackoverflow.com in compatibility mode.
出于 IE 的目的,Intranet 站点包括不路由到外部的面向公众的站点 - 例如,在办公室工作的 Stackoverflow 员工可能会在兼容模式下看到 stackoverflow.com。
回答by ZacNespral21
It worked perfectly for me when i did the folowing:
当我执行以下操作时,它对我来说非常有效:
On http://msdn.microsoft.com/en-us/library/gg699338(v=vs.85).aspx
在http://msdn.microsoft.com/en-us/library/gg699338(v=vs.85).aspx
Used the exact example they provide in the first box(added the missing </html>
at the bottom), opened it in IE10 and standards was forced, i think you may need actual content in the html for it to force standards not sure though.
使用他们在第一个框中提供的确切示例(</html>
在底部添加了缺少的内容),在 IE10 中打开它并强制执行标准,我认为您可能需要 html 中的实际内容来强制执行不确定的标准。
My suggestion would be to replace your empty code with actual content(something simple) and see what it does.
我的建议是用实际内容(一些简单的东西)替换你的空代码,看看它做了什么。