Html <meta http-equiv="X-UA-Compatible" content="IE=edge"> 有什么作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6771258/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:39:58  来源:igfitidea点击:

What does <meta http-equiv="X-UA-Compatible" content="IE=edge"> do?

htmlinternet-explorerbrowserx-ua-compatible

提问by Morgan Cheng

What's the difference if one web page starts with

如果一个网页以

<!DOCTYPE html> 
<html> 
  <head> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 

and If page starts with

如果页面以

<!DOCTYPE html> 
<html> 
  <head> 
     <!-- without X-UA-Compatible meta -->

If there is no difference, I suppose I can just ignore the X-UA-Compatiblemeta header, since I just want it to be rendered in most standard mode in all IE versions.

如果没有区别,我想我可以忽略X-UA-Compatible元标题,因为我只想在所有 IE 版本中以大多数标准模式呈现它。

回答by L84

October 2015 Update

2015 年 10 月更新

This answer was posted several years ago and now the question really should be should you even consider using the X-UA-Compatibletag on your site?with the changes Microsoft has made to its browsers (more on those below).

这个答案是几年前发布的,现在问题真的应该是X-UA-Compatible是否应该考虑在您的网站上使用该标签?随着微软对其浏览器所做的更改(更多内容见下文)。

Depending upon what Microsoft browsers you support you may not need to continue using the X-UA-Compatibletag. If you need to support IE9 or IE8, then I would recommend using the tag. If you only support the latest browsers (IE11 and/or Edge) then I would consider dropping this tag altogether. If you use Twitter Bootstrap and need to eliminate validation warnings, this tag must appear in its specified order. Additional info below:

根据您支持的 Microsoft 浏览器,您可能不需要继续使用该X-UA-Compatible标签。如果您需要支持 IE9 或 IE8,那么我建议您使用该标签。如果您只支持最新的浏览器(IE11 和/或 Edge),那么我会考虑完全删除此标签。如果您使用 Twitter Bootstrap 并需要消除验证警告,则此标签必须按其指定的顺序出现。补充资料如下:



The X-UA-Compatiblemeta tag allows web authors to choose what version of Internet Explorer the page should be rendered as. IE11 has made changes to these modes; see the IE11 note below. Microsoft Edge, the browser that replaced IE11, only honors the X-UA-Compatiblemeta tag in certain circumstances. See the Microsoft Edge note below.

X-UA-Compatible元标记允许网页制作者选择什么版本的Internet Explorer的页面是否应该呈现为。IE11 对这些模式进行了更改;请参阅下面的 IE11 注释。取代 IE11 的浏览器Microsoft EdgeX-UA-Compatible在某些情况下支持元标记。请参阅下面的 Microsoft Edge 说明。

According to Microsoft, when using the X-UA-Compatibletag, it should be as high as possible in your document head:

根据微软的说法,当使用X-UA-Compatible标签时,它应该在你的文档中尽可能高head

If you are using the X-UA-Compatible META tag you want to place it as close to the top of the page's HEAD as possible. Internet Explorer begins interpreting markup using the latest version. When Internet Explorer encounters the X-UA-Compatible META tag it starts over using the designated version's engine. This is a performance hit because the browser must stop and restart analyzing the content.

如果您使用 X-UA-Compatible META 标签,您希望将其放置在尽可能靠近页面 HEAD 顶部的位置。Internet Explorer 开始使用最新版本解释标记。当 Internet Explorer 遇到 X-UA-Compatible META 标记时,它会使用指定版本的引擎重新开始。这是一个性能损失,因为浏览器必须停止并重新开始分析内容。

Here are your options:

以下是您的选择:

  • "IE=edge"
  • "IE=11"
  • "IE=EmulateIE11"
  • "IE=10"
  • "IE=EmulateIE10"
  • "IE=9"
  • "IE=EmulateIE9
  • "IE=8"
  • "IE=EmulateIE8"
  • "IE=7"
  • "IE=EmulateIE7"
  • "IE=5"
  • “IE=边缘”
  • “IE=11”
  • “IE=EmulateIE11”
  • “IE=10”
  • “IE=EmulateIE10”
  • “IE=9”
  • "IE=EmulateIE9
  • “IE=8”
  • “IE=EmulateIE8”
  • “IE=7”
  • “IE=EmulateIE7”
  • “IE=5”

To attempt to understand what each means, here are definitions provided by Microsoft:

为了尝试理解每个含义,以下是 Microsoft 提供的定义:

Internet Explorer supports a number of document compatibility modes that enable different features and can affect the way content is displayed:

  • Edge mode tells Internet Explorer to display content in the highest mode available. With Internet Explorer 9, this is equivalent to IE9 mode. If a future release of Internet Explorer supported a higher compatibility mode, pages set to edge mode would appear in the highest mode supported by that version. Those same pages would still appear in IE9 mode when viewed with Internet Explorer 9. Internet Explorer supports a number of document compatibility modes that enable different features and can affect the way content is displayed:

  • IE11 mode provides the highest support available for established and emerging industry standards, including the HTML5, CSS3 and others.

  • IE10 mode provides the highest support available for established and emerging industry standards, including the HTML5, CSS3 and others.

  • IE9 mode provides the highest support available for established and emerging industry standards, including the HTML5 (Working Draft), W3C Cascading Style Sheets Level 3 Specification (Working Draft), Scalable Vector Graphics (SVG) 1.0 Specification, and others. [Editor Note: IE 9 does notsupport CSS3 animations].

  • IE8 mode supports many established standards, including the W3C Cascading Style Sheets Level 2.1 Specification and the W3C Selectors API; it also provides limited support for the W3C Cascading Style Sheets Level 3 Specification (Working Draft) and other emerging standards.

  • IE7 mode renders content as if it were displayed in standards mode by Internet Explorer 7, whether or not the page contains a directive.

  • Emulate IE9 mode tells Internet Explorer to use the directive to determine how to render content. Standards mode directives are displayed in IE9 mode and quirks mode directives are displayed in IE5 mode. Unlike IE9 mode, Emulate IE9 mode respects the directive.

  • Emulate IE8 mode tells Internet Explorer to use the directive to determine how to render content. Standards mode directives are displayed in IE8 mode and quirks mode directives are displayed in IE5 mode. Unlike IE8 mode, Emulate IE8 mode respects the directive.

  • Emulate IE7 mode tells Internet Explorer to use the directive to determine how to render content. Standards mode directives are displayed in Internet Explorer 7 standards mode and quirks mode directives are displayed in IE5 mode. Unlike IE7 mode, Emulate IE7 mode respects the directive. For many web sites, this is the preferred compatibility mode.

  • IE5 mode renders content as if it were displayed in quirks mode by Internet Explorer 7, which is very similar to the way content was displayed in Microsoft Internet Explorer 5.

Internet Explorer 支持多种文档兼容模式,这些模式启用不同的功能并可能影响内容的显示方式:

  • 边缘模式告诉 Internet Explorer 以可用的最高模式显示内容。对于 Internet Explorer 9,这相当于 IE9 模式。如果 Internet Explorer 的未来版本支持更高的兼容性模式,则设置为边缘模式的页面将以该版本支持的最高模式显示。使用 Internet Explorer 9 查看时,这些相同的页面仍会以 IE9 模式显示。 Internet Explorer 支持多种文档兼容模式,这些模式启用不同的功能并可能影响内容的显示方式:

  • IE11 模式为既定的和新兴的行业标准提供了最高的支持,包括 HTML5、CSS3 和其他标准。

  • IE10 模式为既定的和新兴的行业标准提供了最高的支持,包括 HTML5、CSS3 和其他标准。

  • IE9 模式为既定的和新兴的行业标准提供最高支持,包括 HTML5(工作草案)、W3C 级联样式表级别 3 规范(工作草案)、可缩放矢量图形 (SVG) 1.0 规范等。[编者注:IE 9支持 CSS3 动画]。

  • IE8 模式支持许多既定标准,包括 W3C Cascading Style Sheets Level 2.1 Specification 和 W3C Selectors API;它还为 W3C 级联样式表级别 3 规范(工作草案)和其他新兴标准提供有限的支持。

  • IE7 模式将内容呈现为 Internet Explorer 7 在标准模式下显示的内容,无论页面是否包含指令。

  • 模拟 IE9 模式告诉 Internet Explorer 使用该指令来确定如何呈现内容。标准模式指令以 IE9 模式显示,而怪癖模式指令以 IE5 模式显示。与 IE9 模式不同,Emulate IE9 模式遵守指令。

  • 模拟 IE8 模式告诉 Internet Explorer 使用该指令来确定如何呈现内容。标准模式指令以 IE8 模式显示,而怪癖模式指令以 IE5 模式显示。与 IE8 模式不同,Emulate IE8 模式遵守指令。

  • 模拟 IE7 模式告诉 Internet Explorer 使用该指令来确定如何呈现内容。标准模式指令以 Internet Explorer 7 标准模式显示,而怪癖模式指令以 IE5 模式显示。与 IE7 模式不同,Emulate IE7 模式遵守指令。对于许多网站,这是首选的兼容模式。

  • IE5 模式将内容呈现为 Internet Explorer 7 以 quirks 模式显示的内容,这与 Microsoft Internet Explorer 5 中的内容显示方式非常相似。

IE10 NOTE:As of IE10, quirks mode behaves differently than it did in earlier versions of the browser. In IE9 and earlier versions, quirks mode restricted the webpage to the features supported by IE5.5. In IE10, quirks mode conforms to the differences specified in the HTML5 specification.

IE10 注意:从 IE10 开始,怪癖模式的行为与早期版本的浏览器不同。在 IE9 及更早版本中,怪癖模式将网页限制为 IE5.5 支持的功能。在 IE10 中,怪癖模式符合 HTML5 规范中指定的差异。

Personally, I always choose the http-equiv="X-UA-Compatible" content="IE=edge"meta tag, as older versions have plenty of bugs, and I do not want IE to decide to go into "Compatibility mode" and show my site as IE7 vs IE8 or 9. I always prefer the latest version of IE.

就我个人而言,我总是选择http-equiv="X-UA-Compatible" content="IE=edge"元标记,因为旧版本有很多错误,而且我不希望 IE 决定进入“兼容模式”并将我的网站显示为 IE7 vs IE8 或 9。我总是喜欢最新版本的IE。

IE11

IE11

From Microsoft:

来自微软

Starting with IE11, edge mode is the preferred document mode; it represents the highest support for modern standards available to the browser.

Use the HTML5 document type declaration to enable edge mode:

<!doctype html>

Edge mode was introduced in Internet Explorer 8 and has been available in each subsequent release. Note that the features supported by edge mode are limited to those supported by the specific version of the browser rendering the content.

Starting with IE11, document modes are deprecated and should no longer be used, except on a temporary basis. Make sure to update sites that rely on legacy features and document modes to reflect modern standards.

If you must target a specific document mode so that your site functions while you rework it to support modern standards and features, be aware that you're using a transitional feature, one that may not be available in future versions.

If you currently use the x-ua-compatible header to target a legacy document mode, it's possible your site won't reflect the best experience available with IE11.

从 IE11 开始,边缘模式是首选的文档模式;它代表了对浏览器可用的现代标准的最高支持。

使用 HTML5 文档类型声明启用边缘模式:

<!doctype html>

Edge 模式是在 Internet Explorer 8 中引入的,并且在每个后续版本中都可用。请注意,边缘模式支持的功能仅限于渲染内容的特定浏览器版本支持的功能。

从 IE11 开始,文档模式已弃用,不应再使用,除非是临时使用。确保更新依赖旧功能和文档模式的站点以反映现代标准。

如果您必须针对特定的文档模式,以便您的站点在重新设计以支持现代标准和功能时正常运行,请注意您正在使用过渡功能,该功能可能在未来版本中不可用。

如果您当前使用 x-ua-compatible 标头定位旧文档模式,则您的站点可能无法反映 IE11 的最佳体验。

Microsoft Edge(Replacement for Internet Explorer that comes bundled with Windows 10)

Microsoft Edge(Windows 10 附带的 Internet Explorer 的替代品)

Information on X-UA-Compatiblemeta tag for the "Edge" version of IE. From Microsoft:

有关X-UA-Compatible“Edge”版本 IE 的元标记的信息。来自微软

Introducing the “living” Edge document mode

As we announced in August 2013, we are deprecating document modes as of IE11. With our latest platform updates, the need for legacy document modes is primarily limited to Enterprise legacy web apps. With new architectural changes, these legacy document modes will be isolated from changes in the “living” Edge mode, which will help to guarantee a much higher level of compatibility for customers who depend on those modes and help us move even faster on improvements in Edge. IE will still honor document modes served by intranet sites, sites on the Compatibility View list, and when used with Enterprise Mode only.

Public Internet sites will be rendered with the new Edge mode platform (ignoring X-UA-Compatible). It is our goal that Edge is the "living" document mode from here out and no further document modes will be introduced going forward.

引入“活的”Edge 文档模式

正如我们在 2013 年 8 月宣布的那样,我们将从 IE11 开始弃用文档模式。通过我们最新的平台更新,对旧文档模式的需求主要限于企业旧 Web 应用程序。随着新的架构变化,这些旧文档模式将与“活动”Edge 模式的变化隔离开来,这将有助于为依赖这些模式的客户保证更高级别的兼容性,并帮助我们更快地改进 Edge . IE 仍将支持 Intranet 站点、兼容性视图列表中的站点以及仅与企业模式一起使用时提供的文档模式。

公共 Internet 站点将使用新的 Edge 模式平台呈现(忽略 X-UA-Compatible)。我们的目标是使 Edge 从现在开始成为“活的”文档模式,以后不会引入更多的文档模式。

With the changes in Microsoft Edge to no longer support document modes in most cases, Microsoft has a toolto scan your site to check and see if it has code that is not compatible with Edge.

随着 Microsoft Edge 中的更改在大多数情况下不再支持文档模式,Microsoft 有一个工具可以扫描您的站点以检查它是否有与 Edge 不兼容的代码。

Chrome=1 Info for IE

Chrome=1 IE 信息

There is also chrome=1that you can use or use together with one of the above options like: <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">. chrome=1is for Google's Chrome Frame which is defined as:

还有chrome=1,你可以使用或与像上述选项一起使用:<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">chrome=1适用于 Google 的 Chrome Frame,其定义为:

Google Chrome Frame is an open source browser plug-in. Users who have the plug-in installed have access to Google Chrome's open web technologies and speedy JavaScript engine when they open pages in the browser.

Google Chrome Frame seamlessly enhances your browsing experience in Internet Explorer. It displays Google Chrome Frame enabled sites using Google Chrome's rendering technology, giving you access to the latest HTML5 features as well as Google Chrome's performance and security features without in any way interrupting your usual browser usage.

When Google Chrome Frame is installed, the web just gets better without you having to think about it.

Google Chrome Frame 是一个开源浏览器插件。安装了该插件的用户在浏览器中打开页面时,可以访问 Google Chrome 的开放网络技术和快速的 JavaScript 引擎。

Google Chrome Frame 无缝增强了您在 Internet Explorer 中的浏览体验。它使用 Google Chrome 的渲染技术显示启用 Google Chrome Frame 的站点,让您可以访问最新的 HTML5 功能以及 Google Chrome 的性能和安全功能,而不会以任何方式中断您通常的浏览器使用。

安装 Google Chrome Frame 后,网络会变得更好,而无需您考虑。

But for that plug-in to work you must use chrome=1in the X-UA-Compatiblemeta tag.

但是要使该插件工作,您必须chrome=1X-UA-Compatible元标记中使用。

More info on Chrome Frame can be found here.

可以在此处找到有关 Chrome Frame 的更多信息。

Note:Google Chrome Frame only works for IE6 through IE9, and was retired on February 25, 2014. More info can be found here. Thanks to @mck for the link.

注意:Google Chrome Frame 仅适用于IE6 到 IE9,并于 2014 年 2 月 25 日停用。更多信息可以在这里找到。感谢@mck 提供链接。

Validation:

验证:

HTML5:

HTML5:

The page will validate using the W3 Validatoronly when using <meta http-equiv="X-UA-Compatible" content="IE=Edge">. For other values it will throw the error: A meta element with an http-equiv attribute whose value is X-UA-Compatible must have a content attribute with the value IE=edge.In other words, if you have IE=edge,chrome=1it will not validate. I ignore this error completely as modern browsers simply ignore this line of code.

该页面将验证使用W3验证使用时只<meta http-equiv="X-UA-Compatible" content="IE=Edge">。对于其他值,它会抛出错误:A meta element with an http-equiv attribute whose value is X-UA-Compatible must have a content attribute with the value IE=edge.换句话说,如果你有IE=edge,chrome=1它不会验证。我完全忽略了这个错误,因为现代浏览器只是忽略了这行代码。

If you must have completely valid code then consider doing this on the server level by setting HTTP header. As a note, Microsoft says, If both of these instructions are sent (meta and HTTP), the developer's preference (meta element) takes precedence over the web server setting (HTTP header).See olibre's answeror bitinn's answerfor more details on how to set an HTTP header.

如果您必须拥有完全有效的代码,请考虑通过设置 HTTP 标头在服务器级别执行此操作。请注意,微软表示,If both of these instructions are sent (meta and HTTP), the developer's preference (meta element) takes precedence over the web server setting (HTTP header).有关如何设置 HTTP 标头的更多详细信息,请参阅olibre 的回答bitinn 的回答

XHTML

XHTML

There isn't an issue with validation when using <meta http-equiv="X-UA-Compatible" content="IE=Edge" />as long as the tag is properly closed (i.e. />vs >).

<meta http-equiv="X-UA-Compatible" content="IE=Edge" />只要标签正确关闭(即/>vs >),使用时验证就没有问题。

Twitter Bootstrap

推特引导程序

This tag has been strongly recommended by the Bootstrap team since at least 2014, and Bootlint, the linter authored by the twbs team continues to throw a warningwhen the tag is omitted. The linter distinguishes between warnings and errors, and as such the severity of omitting this tag may be considered minor.

至少从 2014 年开始,Bootstrap 团队就一直强烈推荐这个标签,而Bootlint是由 twbs 团队编写的 linter,当该标签被省略时,它会继续发出警告。linter 区分警告和错误,因此忽略此标签的严重性可能被认为是次要的。



For more information on X-UA-Compatiblesee Microsoft's Website Defining Document Compatibility.

有关详细信息,X-UA-Compatible请参阅 Microsoft 的网站定义文档兼容性

For more information on what IE supports see caniuse.com.

有关 IE 支持的更多信息,请访问caniuse.com

For more information on Twitter Bootstrap requirements, see the bootlint project wiki page.

有关 Twitter Bootstrap 要求的更多信息,请参阅 bootlint 项目wiki 页面

回答by olibre

Use content="IE=edge,chrome=1"  Skip other X-UA-Compatiblemodes

使用content="IE=edge,chrome=1"  跳过其他X-UA-Compatible模式

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
                                   -------------------------- 
  • No compatibility icon
    The IE9 Address bar does not show up the Compatibility View button
    and the page does not also show up a jumble of out-of-place menus, images, and text boxes.

  • Features
    This meta tag is required to enable javascript::JSON.parse()on IE8
    (even when <!DOCTYPE html>is present)

  • Correctness
    Rendering/Execution of modern HTML/CSS/JavaScript is more valid (nicer).

  • Performance
    The Trident rendering engineshould run faster in its edgemode.

  • 没有兼容性图标
    IE9 地址栏没有显示兼容性视图按钮
    ,页面也没有显示乱七八糟的菜单、图像和文本框。

  • 特性
    这个元标记需要javascript::JSON.parse()在 IE8上启用
    (即使<!DOCTYPE html>存在)


  • 现代 HTML/CSS/JavaScript 的正确性渲染/执行更有效(更好)。

  • 性能
    三叉戟渲染引擎应该运行在它的速度更快边缘模式。



Usage

用法

In your HTML

在你的 HTML

<!DOCTYPE html> 
<html> 
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

Or better in the configuration of your web server:
(see also the RiaD's answer)

或者更好地配置您的 Web 服务器:(
另请参阅RiaD 的回答

  • Apacheas proposed by pixeline

    <IfModule mod_setenvif.c>
      <IfModule mod_headers.c>
        BrowserMatch MSIE ie
        Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
      </IfModule>
    </IfModule>
    <IfModule mod_headers.c>
      Header append Vary User-Agent
    </IfModule>
    
  • Nginxas proposed by Stef Pause

    server {
      #...
      add_header X-UA-Compatible "IE=Edge,chrome=1";
    }
    
  • Varnishproxy as proposed by Lucas Riutzel

    sub vcl_deliver {
      if( resp.http.Content-Type ~ "text/html" ) {
        set resp.http.X-UA-Compatible = "IE=edge,chrome=1";
      }
    }
    
  • IIS(since v7)

    <configuration>
      <system.webServer>
         <httpProtocol>
            <customHeaders>
               <add name="X-UA-Compatible" value="IE=edge,chrome=1" />
            </customHeaders>
         </httpProtocol>
      </system.webServer>
    </configuration>
    
  • Apache的提议pixeline

    <IfModule mod_setenvif.c>
      <IfModule mod_headers.c>
        BrowserMatch MSIE ie
        Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
      </IfModule>
    </IfModule>
    <IfModule mod_headers.c>
      Header append Vary User-Agent
    </IfModule>
    
  • Stef Pause提出的Nginx

    server {
      #...
      add_header X-UA-Compatible "IE=Edge,chrome=1";
    }
    
  • Lucas Riutzel提出的清漆代理

    sub vcl_deliver {
      if( resp.http.Content-Type ~ "text/html" ) {
        set resp.http.X-UA-Compatible = "IE=edge,chrome=1";
      }
    }
    
  • IIS(自 v7 起)

    <configuration>
      <system.webServer>
         <httpProtocol>
            <customHeaders>
               <add name="X-UA-Compatible" value="IE=edge,chrome=1" />
            </customHeaders>
         </httpProtocol>
      </system.webServer>
    </configuration>
    


Microsoft recommends Edge modesince IE11

微软自 IE11 起推荐Edge 模式

As noticed by Lynda(see comments), the Compatibility changes in IE11recommends Edge mode:

正如Lynda所注意到的(见评论),IE11 中兼容性更改建议使用Edge 模式

Starting with IE11, edge mode is the preferred document mode; it represents the highest support for modern standards available to the browser.

从 IE11 开始,边缘模式是首选的文档模式;它代表了对浏览器可用的现代标准的最高支持。

But the position of Microsoft was not clear.Another MSDN page did not recommend Edge mode:

但微软的立场并不明确。另一个MSDN 页面不推荐Edge 模式

Because Edge mode forces all pages to be opened in standards mode, regardless of the version of Internet Explorer, you might be tempted to use this for all pages viewed with Internet Explorer. Don't do this, as the X-UA-Compatibleheader is only supported starting with Windows Internet Explorer 8.

因为边缘模式强制以标准模式打开所有页面,而不管 Internet Explorer 的版本如何,您可能想对使用 Internet Explorer 查看的所有页面使用此模式。不要这样做,因为X-UA-Compatible仅从 Windows Internet Explorer 8 开始支持标头。

Instead, Microsoft recommended using <!DOCTYPE html>:

相反,微软建议使用<!DOCTYPE html>

If you want all supported versions of Internet Explorer to open your pages in standards mode, use the HTML5 document type declaration [...]

如果您希望所有受支持的 Internet Explorer 版本都以标准模式打开您的页面,请使用 HTML5 文档类型声明 [...]

As Ricardoexplains (in the comments below) any DOCTYPE (HTML4, XHTML1...) can be used to trigger Standards Mode, not only HTML5's DOCTYPE. The important thing is to always have a DOCTYPE in the page.

正如Ricardo解释的(在下面的评论中)任何 DOCTYPE(HTML4、XHTML1...)都可以用来触发标准模式,而不仅仅是 HTML5 的 DOCTYPE。重要的是在页面中始终有一个 DOCTYPE。

Clara Onagerhas even noticed in an older version of Specifying legacy document modes:

Clara Onager甚至在旧版本的指定旧文档模式中注意到:

Edge mode is intended for testing purposes only; do not use it in a production environment.

边缘模式仅用于测试目的;不要在生产环境中使用它。

It is so confusing that Usman Ythought Clara Onagerwas speaking about:

乌斯曼·Y认为克拉拉·奥纳格( Clara Onager) 说的是如此令人困惑:

The [...] example is provided for illustrative purposes only; don't use it in a production environment.

<meta http-equiv="X-UA-Compatible" content="IE=7,9,10" >

[...] 示例仅用于说明目的;不要在生产环境中使用它。

<meta http-equiv="X-UA-Compatible" content="IE=7,9,10" >

Well... In the rest of this answer I give more explanations why using content="IE=edge,chrome=1"is a good practice in production.

嗯......在这个答案的其余部分中,我给出了更多解释为什么使用content="IE=edge,chrome=1"是生产中的一个好习惯。



History

历史

For many years (2000 to 2008), IE market share was more than 80%. And IE v6was considered as a de factostandard (80% to 97% market share in 2003, 2004, 2005 and 2006for IE6 only, more market share with all IE versions).

多年来(2000 年至 2008 年),IE 市场份额超过 80%。并且 IE v6被认为是事实上的标准(2003 年2004 年、2005 年和 2006年仅 IE6 的市场份额为80% 至 97% ,所有 IE 版本的市场份额都更大)。

As IE6 was not respecting Web standards, developers hadto test their website using IE6. That situation was great for Microsoft (MS) as web developers had to buyMS products (e.g. IE cannot be used without buying Windows), and it was more profit-making to stay non-compliant (i.e. Microsoft wanted to become thestandard excluding other companies).

由于 IE6 不遵守Web 标准,开发人员不得不使用 IE6 测试他们的网站。这种情况对微软(MS)来说很好,因为 Web 开发人员必须购买MS 产品(例如,不购买 Windows 就无法使用 IE),而保持不合规更有利可图(即,微软希望成为排除其他产品标准)公司)。

Therefore many many sites were IE6 compliant only, and as IE was not compliant with web standard, all these web sites was not well rendered on standards compliant browsers. Even worse, many sites required only IE.

因此,许多网站只兼容 IE6,而由于 IE 不符合 Web 标准,所有这些网站在符合标准的浏览器上都不能很好地呈现。更糟糕的是,许多站点只需要 IE

However, at this time, Mozilla started Firefox development respecting as much as possible all the web standards (other browser were implemented to render pages as done by IE6). As more and more web developers wanted to use the new web standards features, more and more websites were more supported by Firefox than IE.

然而,此时,Mozilla 开始了 Firefox 的开发,尽可能地尊重所有的 Web 标准(其他浏览器实现了像 IE6 那样呈现页面)。随着越来越多的 Web 开发人员想要使用新的 Web 标准功能,Firefox 比 IE 更支持越来越多的网站。

When IE market sharing was decreasing, MS realized staying standard incompatible was not a good idea. Therefore MS started to release new IE version (IE8/IE9/IE10) respecting more and more the web standards.

当 IE 市场份额下降时,MS 意识到保持标准不兼容并不是一个好主意。因此,MS 开始发布新的 IE 版本(IE8/IE9/IE10),越来越尊重 Web 标准。



The web-incompatible issue

网络不兼容问题

But the issue is all the websites designed for IE6: Microsoft could not release new IE versions incompatible with these old IE6-designed websites. Instead of deducing the IE version a website has been designed, MS requested developers to add extra data (X-UA-Compatible) in their pages.

但问题是所有为 IE6 设计的网站:微软无法发布与这些旧的 IE6 设计的网站不兼容的新 IE 版本。MS 并没有推断网站设计的 IE 版本,而是要求开发人员X-UA-Compatible在他们的页面中添加额外的数据 ( )。

IE6 is still used in 2016

2016年还在用IE6

Nowadays, IE6 is still used (0.7% in 2016)(4.5% in January 2014), and some internet websites are still IE6-only-compliant. Some intranet website/applications are tested using IE6. Some intranet website are 100% functional only on IE6. These companies/departments prefer to postpone the migration cost: other priorities, nobody no longer knows how the website/application has been implemented, the owner of the legacy website/application went bankrupt...

如今,IE6 仍在使用(2016 年为 0.7%)(2014 年 1 月为 4.5%),并且一些互联网网站仍然只兼容 IE6。部分内网网站/应用程序使用 IE6 进行测试。一些内网网站只能在 IE6 上 100% 运行。这些公司/部门更愿意推迟迁移成本:其他优先事项,没有人知道网站/应用程序是如何实施的,遗留网站/应用程序的所有者破产了......

China represents 50% of IE6 usage in 2013, but it may change in the next years as Chinese Linux distribution is being broadcast.

china占 2013 年 IE6 使用量的 50%,但随着china Linux 发行版的普及,未来几年可能会发生变化。

Be confident with your web skills

对您的网络技能充满信心

If you (try to) respect web standard, you can simply always use http-equiv="X-UA-Compatible" content="IE=edge,chrome=1". To keep compatibility with old browsers, just avoid using latest web features: use the subset supported by the oldest browser you want to support. Or If you want to go further, you may adopt concepts as Graceful degradation, Progressive enhancementand Unobtrusive JavaScript. (You may also be pleased to read What should a web developer consider?.)

如果您(尝试)尊重 Web 标准,则可以始终使用http-equiv="X-UA-Compatible" content="IE=edge,chrome=1". 为了保持与旧浏览器的兼容性,请避免使用最新的 Web 功能:使用您想要支持的最旧浏览器支持的子集。或者,如果你想更进一步,你可以采用优雅降级渐进增强和非侵入式 JavaScript 等概念。(您可能也很高兴阅读Web 开发人员应该考虑什么?。)

Do do not care about the best IE version rendering: this is not your job as browsers have to be compliant with web standards. If your site is standard compliant and use moderately latest features, therefore browsers have to be compliant with your website.

不要关心最好的 IE 版本渲染:这不是您的工作,因为浏览器必须符合 Web 标准。如果您的网站符合标准并使用最新的功能,则浏览器必须与您的网站兼容

Moreover, as there are many campaigns to killIE6 (IE6 no more, MS campaign), nowadays you may avoid wasting time with IE testing!

此外,由于有许多活动可以杀死IE6(不再是 IE6MS 活动),现在您可以避免在 IE 测试上浪费时间!

Personal IE6 experience

个人IE6体验

In 2009-2012, I worked for a company using IE6 as the official single browser allowed. I had to implement an intranet website for IE6 only. I decided to respect web standard but using the IE6-capable subset (HTML/CSS/JS).

2009-2012年,我在一家使用IE6作为官方单一浏览器的公司工作。我只需要为 IE6 实现一个 Intranet 网站。我决定尊重 Web 标准,但使用支持 IE6 的子集(HTML/CSS/JS)。

It was hard, but when the company switched to IE8, the website was still well rendered because I had used Firefox and firebugto check the web-standard compatibility ;)

这很难,但是当公司切换到 IE8 时,网站仍然呈现得很好,因为我使用了 Firefox 和firebug来检查网络标准兼容性;)

回答by andrewdotn

The difference is that if you only specify the DOCTYPE, IE's Compatibility View Settingstake precedence. By default these settings force all intranet sites into Compatibility View regardless of DOCTYPE. There's also a checkbox to use Compatibility View for all websites, regardless of DOCTYPE.

不同之处在于,如果仅指定DOCTYPE,则 IE 的兼容性视图设置优先。默认情况下,这些设置强制所有 Intranet 站点进入兼容性视图,无论DOCTYPE. 还有一个复选框可以为所有网站使用兼容性视图,无论DOCTYPE.

IE Compatibility View Settings dialog

IE Compatibility View Settings dialog

X-UA-Compatibleoverrides the Compatibility View Settings, so the page will render in standards mode regardless of the browser settings. This forces standards mode for:

X-UA-Compatible覆盖兼容性视图设置,因此无论浏览器设置如何,页面都将以标准模式呈现。这将强制标准模式用于:

  • intranet pages
  • external web pages when the computer administrator has chosen “Display all websites in Compatibility View” as the default—think big companies, governments, universities
  • when you unintentionally end up on the Microsoft Compatibility View List
  • cases where users have manually added your website to the list in Compatibility View Settings
  • 内网页面
  • 当计算机管理员选择“在兼容性视图中显示所有网站”作为默认设置时的外部网页——想想大公司、政府、大学
  • 当您无意中出现在Microsoft 兼容性视图列表中时
  • 用户手动将您的网站添加到兼容性视图设置中的列表的情况

DOCTYPEalone cannot do that; you will end up in one of the Compatibility View modes in these cases regardless of DOCTYPE.

DOCTYPE独自不能做到这一点;在这些情况下,无论DOCTYPE.

If both the metatag and the HTTP header are specified, the metatag takes precedence.

如果同时meta指定了标签和 HTTP 标头,则meta标签优先。

This answer is based on examining the complete rules for deciding document mode in IE8, IE9, and IE10. Note that looking at the DOCTYPEis the very last fallback for deciding the document mode.

此答案基于检查在IE8IE9IE10 中决定文档模式的完整规则。请注意,查看DOCTYPE是决定文档模式的最后一个后备。

回答by George Filippakos

Use this to force IE to hide that annoying browser compatibility button in the address bar:

使用它来强制 IE 在地址栏中隐藏那个烦人的浏览器兼容性按钮:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

回答by EMurph78

Since I can not add a comment to the marked answer I will just post this here.

由于我无法对标记的答案添加评论,因此我将在此处发布。

In addition to the correct answer you can indeed have this validated. Since this meta tag is only directed for IE all you need to do is add a IE conditional.

除了正确答案之外,您确实可以对此进行验证。由于此元标记仅针对 IE,因此您需要做的就是添加 IE 条件。

<!--[if IE]>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<![endif]-->

Doing this is just like adding any other IE conditional statement and only works for IE and no other browsers will be affected.

这样做就像添加任何其他 IE 条件语句一样,仅适用于 IE,不会影响其他浏览器。

回答by James Tsai

I think this diagram from Microsoft explains all. In order to tell IE how to render the content, !DOCTYPE has to work with X-UA-Compatible meta tag. !DOCTYPE by itself has no affect on changing IE Document Mode.

我认为微软的这张图说明了一切。为了告诉 IE 如何呈现内容,!DOCTYPE 必须使用 X-UA-Compatible 元标记。!DOCTYPE 本身对更改 IE 文档模式没有影响。

enter image description here

enter image description here

http://ie.microsoft.com/testdrive/ieblog/2010/Mar/02_HowIE8DeterminesDocumentMode_3.png

http://ie.microsoft.com/testdrive/ieblog/2010/Mar/02_HowIE8DeterminesDocumentMode_3.png

回答by bitinn

Just for completeness, you don't actually have to add it to your HTML (which is unknown http-equiv in HTML5)

为了完整起见,您实际上不必将其添加到您的 HTML 中(在 HTML5 中这是未知的 http-equiv)

Do this and never look back (first example for apache, second for nginx)

这样做并且永远不要回头(第一个例子是apache,第二个例子是nginx

Header set X-UA-Compatible "IE=Edge,chrome=1"

add_header X-UA-Compatible "IE=Edge,chrome=1";

回答by Bipon Biswas

Just one sentence to say Instruct Internet Explorer to use its latest rendering engine

只需一句话说指示 Internet Explorer 使用其最新的渲染引擎

<meta http-equiv="x-ua-compatible" content="ie=edge">

回答by ToniTornado

<meta http-equiv="X-UA-Compatible" content="IE=Edge">

To make this line work as expected, make sure that:

要使这条线按预期工作,请确保:

  1. It is the first element right after <head>
  2. No conditional commentsare used before the meta tag, e. g. on the <html>element
  1. 它是紧随其后的第一个元素 <head>
  2. 在元标记之前不使用条件注释,例如在<html>元素上

Otherwise some IE versions simply ignore it.

否则某些 IE 版本会直接忽略它。

UPDATE

更新

These two rules are simplified but they are easy to remember and to verify. Despite MSDN docs stating you can put title and other meta tags before this one, I would not recommend to do so.

这两个规则被简化了,但它们很容易记住和验证。尽管 MSDN 文档指出您可以在此之前放置标题和其他元标记,但我不建议这样做。

How make it work with conditional comments.

如何使其与条件注释一起工作。

Interesting article about the order of elements in the head.(blogs.msdn.com, for IE)

关于头部元素顺序的有趣文章。(blogs.msdn.com,适用于 IE)

REFERENCE

参考

From the MSDN documentation:

MSDN 文档

The X-UA-Compatible[...] must appear in the header of the webpage (the HEAD section) before all other elements except for the title element and other meta elements.

X-UA-Compatible[...]必须出现在标题以外的元件和其他元元素的所有其他元件之前的网页(HEAD部分)的报头。

回答by ?ukasz Jakóbiec

if you use your website in the same network as the server IE likes to switch to compability modedespite DOCTYPE.
Adding meta http-equiv="X-UA-Compatible" content="IE=Edge"disablesthis unwanted behaviour.

如果您在与服务器相同的网络中使用您的网站,尽管 DOCTYPE IE 喜欢切换到兼容模式
添加meta http-equiv="X-UA-Compatible" content="IE=Edge"会禁用这种不需要的行为。