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

标签 html internet-explorer browser x-ua-compatible

如果一个网页以

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

如果页面以
<!DOCTYPE html> 
<html> 
  <head> 
     <!-- without X-UA-Compatible meta -->

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

最佳答案

2015 年 10 月更新

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

根据您支持的 Microsoft 浏览器,您可能不需要继续使用 X-UA-Compatible标签。如果您需要支持 IE9 或 IE8,那么我建议您使用该标签。如果您只支持最新的浏览器(IE11 和/或 Edge),那么我会考虑完全删除此标签。如果您使用 Twitter Bootstrap 并需要消除验证警告,则此标签必须按其指定的顺序出现。补充资料如下:
X-UA-Compatible元标记允许网络作者选择页面应该呈现为什么版本的 Internet Explorer。 IE11 对这些模式进行了更改;请参阅下面的 IE11 注释。 Microsoft Edge ,取代IE11的浏览器,只尊重X-UA-Compatible某些情况下的元标记。请参阅下面的 Microsoft Edge 说明。

据微软称,在使用 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.



以下是您的选择:
  • “IE=边缘”
  • "IE=11"
  • "IE=EmulateIE11"
  • "IE=10"
  • "IE=EmulateIE10"
  • "IE=9"
  • "IE=EmulateIE9
  • "IE=8"
  • "IE=EmulateIE8"
  • "IE=7"
  • "IE=EmulateIE7"
  • "IE=5"

  • 为了尝试理解每个含义,以下是 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 not support 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.



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

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

    IE11

    来自 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.



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

    信息X-UA-Compatible IE 的“Edge”版本的元标记。 From Microsoft :

    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.



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

    Chrome=1 IE 信息

    还有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.



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

    有关 Chrome Frame 的更多信息,请访问 here .

    注: Google Chrome Frame 仅适用于 IE6 through IE9 , 并于 2014 年 2 月 25 日退休。更多信息可以找到 here .感谢@mck 提供链接。

    验证:

    HTML5 :

    该页面将使用 W3 Validator 进行验证仅在使用 <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它不会验证。我完全忽略了这个错误,因为现代浏览器只是忽略了这行代码。

    如果您必须拥有完全有效的代码,请考虑通过设置 HTTP header 在服务器级别执行此操作。作为说明,微软说,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).olibre's answerbitinn's answer有关如何设置 HTTP header 的更多详细信息。

    XHTML

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

    Twitter bootstrap

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

    更多信息X-UA-Compatible参见微软的 Website Defining Document Compatibility .

    有关 IE 支持的更多信息,请参阅 caniuse.com .

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

    关于html - &lt;meta http-equiv ="X-UA-Compatible"content ="IE=edge"> 有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6771258/

    相关文章:

    internet-explorer - Internet Explorer 中的 Blazor

    javascript - 如何处理 IE11 中偶尔错误的 offsetWidths/Heights

    html - WPF 框架 - 在外部浏览器中打开链接

    html - 列表元素符号在 Internet Explorer 中无法正确显示

    html - 移动设备右侧不需要的空白

    javascript - 当 body 滚动时滚动一个元素

    所有浏览器中的 JavaScript 和 jQuery 滚动问题

    javascript - 第二次单击后按钮不起作用

    css - IE11/Edge buggy box-shadow渲染

    c# - 从 .Net WinForms 应用程序以编程方式刷新浏览器页面