IE10 以 IE7 模式呈现.如何强制标准模式? [英] IE10 renders in IE7 mode. How to force Standards mode?

查看:42
本文介绍了IE10 以 IE7 模式呈现.如何强制标准模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在微软的网站上,他们声称简单的 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>

http://d.pr/i/fvzb+

推荐答案

Internet Explorer 假设大多数网页都是针对早期版本的 IE 编写的,并查看文档类型、元标记和 HTML 以确定最佳兼容模式(有时不正确).即使使用 HTML5 文档类型,如果您的网站是 Intranet 站点,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.

为确保您的网站始终使用最新的标准模式,您可以确保关闭以兼容方式显示 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 have to do this on each machine local to the web server (instructions are below).

或者,更好的是,您可以使用 X-UA-Compatible 标头从服务器关闭此功能.重要的是要注意使用元标记将不起作用!

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 中,都提到使用主机标头或元标记甚至应该覆盖 Intranet 站点.文章 了解 Internet Explorer 中的兼容模式8 说明如下.

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.

大量内部商业网站针对 Internet Explorer 7 进行了优化,因此此默认例外保留了这种兼容性....同样,如果使用 Meta 标记或 http 标头为文档设置兼容模式,它将覆盖这些设置.

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.

然而,在实践中这是行不通的,使用主机头是唯一可行的选择.文章的评论部分还显示了这个确切问题的许多示例.

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-Compatible 标头

如果您使用 .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 文档类型一起存在,网站将始终以最新的标准模式运行.

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 站点.

您可以通过点击 Alt 来获取菜单.

You can bring this up by hitting Alt to get the menu.

编辑这个答案也适用于 IE9.

Edit This answer also pertains to IE9.

这篇关于IE10 以 IE7 模式呈现.如何强制标准模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆