Html IE 兼容模式:'X-UA-Compatible' 标签 'Edge'

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

IE Compatibility Mode: 'X-UA-Compatible' tag 'Edge'

htmlinternet-explorercross-browserx-ua-compatible

提问by Jonathan

I have this in the <head>:

我有这个<head>

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

It will force the latest rendering mode for IE, but is Compatibility Mode considered the last one?

它将强制 IE 使用最新的渲染模式,但兼容模式是否被认为是最后一种?

I mean, for example: using this code with IE8, it will force it to use IE8 or IE8 Compatibility Mode?

我的意思是,例如:将此代码与 IE8 一起使用,它会强制它使用 IE8 或 IE8 兼容模式吗?

回答by oldwizard

That tag will try to force the browser to use the latest rendering mode the browser supports. It will not trigger Compatibility mode.

该标签将尝试强制浏览器使用浏览器支持的最新渲染模式。它不会触发兼容模式。

Note that the tag has to be the first tag in the head or it will not work. This fact favors using HTTP headers if possible as the order in the HTTP headers does not matter.

请注意,标签必须是头部的第一个标签,否则将无法工作。这个事实有利于尽可能使用 HTTP 标头,因为 HTTP 标头中的顺序无关紧要。

If the browser stills ends up in Compatibility mode when you use a header or the meta tag one of these things is likely the cause:

如果在使用标头或元标记时浏览器仍然以兼容模式结束,可能是以下原因之一:

  • you are missing a sane doctype
  • the browser has been set to always use compatibility mode
  • the site is hosted on an "intranet site" and the default setting for intranet sites is set
  • 你缺少一个理智的文档类型
  • 浏览器已设置为始终使用兼容模式
  • 该站点托管在“内部网站点”上,并且已设置内部网站点的默认设置

Changing the browsers Compatibility View settings

更改浏览器兼容性视图设置

Microsoft considers at least 192.168.x.x to be on a "Intranet site". The default for intranet sites in IE8/IE9 is to use compatibility mode. That's a huge issue for many business applications as the programmer CANNOT override this option even with this meta tag. ("Display intranet sites in Compatitiblity View" is not overridable by meta tag or http header - the browser is in complete control of compatibility view in this case)

Microsoft 认为至少 192.168.xx 位于“Intranet 站点”上。IE8/IE9 内网站点默认使用兼容模式。对于许多业务应用程序来说,这是一个大问题,因为即使使用此元标记,程序员也无法覆盖此选项。(“在兼容性视图中显示 Intranet 站点”不能被元标记或 http 标头覆盖 - 在这种情况下,浏览器完全控制兼容性视图)

Compatibility View Settings

兼容性视图设置

Always add this meta tag or an http header?

总是添加此元标记或 http 标头?

One more good thing about using this meta tag is that the "compatibilty view" icon is removed from the address bar of the browser. At least your users can then not decide the render mode using that button.

使用此元标记的另一个好处是“兼容性视图”图标已从浏览器的地址栏中删除。至少您的用户无法使用该按钮决定渲染模式。

回答by rshadman

Even if you have unchecked the "Display intranet sites in Compatibility View" option, and have the X-UA-Compatible in your response headers, there is another reason why your browser might default to "Compatibility View" anyways - your Group Policy. Look at your console for the following message:

即使您已取消选中“在兼容性视图中显示 Intranet 站点”选项,并在响应标头中包含 X-UA-Compatible,您的浏览器仍可能默认为“兼容性视图”的另一个原因 - 您的组策略。查看您的控制台以获取以下消息:

HTML1203: xxx.xxx has been configured to run in Compatibility View through Group Policy.

HTML1203:xxx.xxx 已配置为通过组策略在兼容性视图中运行。

Where xxx.xxx is the domain for your site (i.e. test.com). If you see this then the group policy for your domain is set so that any site ending in test.com will automatically render in Compatibility mode regardless of doctype, headers, etc.

其中 xxx.xxx 是您站点的域(即 test.com)。如果您看到此信息,则您的域的组策略已设置,以便任何以 test.com 结尾的站点都将自动以兼容模式呈现,而不管文档类型、标题等如何。

For more information, please see the following link (explains the html codes): http://msdn.microsoft.com/en-us/library/ie/hh180764(v=vs.85).aspx

有关详细信息,请参阅以下链接(解释 html 代码):http: //msdn.microsoft.com/en-us/library/ie/hh180764(v=vs.85) .aspx

回答by MelanieMenard

I'm not an expert but by trial and error:

我不是专家,但通过反复试验:

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

solved the problem for me. I used this on websites and webapps and it stopped IE8 from going into compatibility mode, and displayed as 'standard' in IE10 and IE11.

为我解决了这个问题。我在网站和 webapps 上使用了它,它阻止了 IE8 进入兼容模式,并在 IE10 和 IE11 中显示为“标准”。

回答by unclenorton

What is the point of using the Edgekeyword alone? I mean, if you want IE to use the most recent rendering engine, then just drop the whole meta tag.

Edge单独使用关键字有什么意义?我的意思是,如果您希望 IE 使用最新的渲染引擎,那么只需删除整个元标记。

Otherwise, it should look something like that (that would make IE8 behave like IE7 and IE9 and newer will work as usual) :

否则,它应该看起来像这样(这将使 IE8 的行为类似于 IE7 和 IE9,更新版本将照常工作):

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