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

html HTML

米亚神无

2020-03-13

如果一个网页以...开头有什么区别

<!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版本中以最标准的方式呈现它。

第1568篇《<meta http-equiv =“ X-UA-Compatible” content =“ IE = edge”>有什么作用?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

9个回答
小宇宙乐理查德 2020.03.13

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

阿飞GO 2020.03.13

仅出于完整性考虑,您实际上不必将其添加到HTML(HTML5中未知的http-equiv)。

做到这一点,永远不要回头(第一个示例apache,第二个示例nginx

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

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

只需说一句即可指示Internet Explorer使用其最新的呈现引擎

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

这实际上是1个Google查询,但是这里是:

http://msdn.microsoft.com/zh-CN/library/jj676915(v=vs.85).aspx

了解旧版文档模式

使用以下值从Internet Explorer 6到IE11以边缘模式显示网页,这是Internet Explorer支持的最高标准模式。

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

请注意,这在功能上等同于使用HTML5文档类型。它将Internet Explorer置于受支持最高的文档模式。Edge最适合定期维护的网站,这些网站经过例行测试,可以在多个浏览器(包括Internet Explorer)之间进行互操作。

注意 从IE11开始,边缘模式被认为是首选的文档模式。(在早期版本中,它被认为是实验性的。)要了解更多信息,请参阅不建议使用文档模式。从Windows Internet Explorer 8开始,一些Web开发人员使用边缘模式元元素来隐藏地址栏上的“兼容性视图”按钮。从IE11开始,不再需要此按钮,因为该按钮已从地址栏中删除。因为它强制所有页面以标准模式打开,而不管Internet Explorer的版本如何,所以您可能会倾向于对Internet Explorer查看的所有页面使用边缘模式。不要这样做,因为仅从Internet Explorer 8开始才支持X-UA-Compatible标头。

提示 如果希望所有受支持的Internet Explorer版本以标准模式打开页面,请使用HTML5文档类型声明,如前面的示例所示。

搜索结果中还有:

米亚Stafan 2020.03.13
<meta http-equiv="X-UA-Compatible" content="IE=Edge">

要使此行按预期工作,请确保:

  1. 这是紧随其后的第一个元素 <head>
  2. 在meta标记之前(例如在元素上)不使用任何条件注释<html>

否则,某些IE版本只会忽略它。

更新

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

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

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

参考

MSDN文档中

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

小胖逆天 2020.03.13

The difference is that if you only specify the DOCTYPE, IE’s Compatibility View Settings take 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.

IE兼容性视图设置对话框

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

  • 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

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

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

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

小宇宙猴子 2020.03.13

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

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

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

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

蛋蛋L 2020.03.13

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

在此处输入图片说明

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

老丝Gil樱 2020.03.13

使用此选项可强制IE在地址栏中隐藏该烦人的浏览器兼容性按钮:

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

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android