Html 使用标签强制关闭 IE 兼容模式

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

Force IE compatibility mode off using tags

htmlinternet-explorer

提问by Al Katawazi

I am doing work for a client who forces compatibility mode on all intranet sites. I was wondering if there is a tag I can put into my HTML that forces compatibility mode off.

我正在为在所有 Intranet 站点上强制使用兼容模式的客户工作。我想知道是否有一个标签可以放入我的 HTML 中,强制关闭兼容模式。

回答by Pekka

There is the "edge" mode.

有“边缘”模式

<html>
   <head>
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <title>My Web Page</title>
   </head>
   <body>
      <p>Content goes here.</p>
   </body>
</html>

From the linked MSDN page:

从链接的 MSDN 页面:

Edge mode tells Windows Internet Explorer to display content in the highest mode available, which actually breaks the “lock-in” paradigm. With Internet Explorer 8, this is equivalent to IE8 mode. If a (hypothetical) 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; however, those same pages would still appear in IE8 mode when viewed with Internet Explorer 8.

边缘模式告诉 Windows Internet Explorer 以可用的最高模式显示内容,这实际上打破了“锁定”范式。对于 Internet Explorer 8,这相当于 IE8 模式。如果(假设的)未来版本的 Internet Explorer 支持更高的兼容模式,则设置为边缘模式的页面将显示为该版本支持的最高模式;但是,当使用 Internet Explorer 8 查看时,这些相同的页面仍会出现在 IE8 模式下。

However, "edge" mode is not encouraged in production use:

但是,不鼓励在生产使用中使用“边缘”模式:

It is recommended that Web developers restrict their use of Edge mode to test pages and other non-production uses because of the possible unexpected results of rendering page content in future versions of Windows Internet Explorer.

建议 Web 开发人员将边缘模式的使用限制为测试页面和其他非生产用途,因为在未来版本的 Windows Internet Explorer 中呈现页面内容可能会出现意外结果。

I honestly don't entirely understand why. But according to this, the best way to go at the moment is using IE=8.

老实说,我不完全明白为什么。但根据这一点,目前最好的方法是使用IE=8.

回答by brandonjp

After many hours troubleshooting this stuff... Here are some quick highlights that helped us from the X-UA-Compatibledocs: http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx#ctl00_contentContainer_ctl16

经过几个小时的故障排除后...这里有一些快速的亮点,帮助我们从X-UA-Compatible文档:http: //msdn.microsoft.com/en-us/library/cc288325(VS.85) .aspx#ctl00_contentContainer_ctl16

Using <meta http-equiv="X-UA-Compatible" content=" _______ " />

使用 <meta http-equiv="X-UA-Compatible" content=" _______ " />

  • The Standard User Agentmodes (the non-emulate ones) ignore <!DOCTYPE>directives in your page and render based on the standards supported by that version of IE (e.g., IE=8will better obey table border spacing and some pseudo selectors than IE=7).

  • Whereas, the Emulatemodes tell IE to follow any <!DOCTYPE>directives in your page, rendering standards mode based the version you choose and quirks mode based on IE=5

  • Possible values for the contentattribute are:

    content="IE=5"

    content="IE=7"

    content="IE=EmulateIE7"

    content="IE=8"

    content="IE=EmulateIE8"

    content="IE=9"

    content="IE=EmulateIE9"

    content="IE=edge"

  • 标准的用户代理模式(非模拟的)忽略<!DOCTYPE>在页面指令和渲染基于该版本的IE浏览器所支持的标准(例如,IE=8将更好地服从表格边框间距和一些伪选择比IE=7)。

  • Emulate模式告诉 IE 遵循<!DOCTYPE>页面中的任何指令,呈现基于您选择的版本的标准模式和基于的 quirks 模式IE=5

  • content属性的可能值为:

    content="IE=5"

    content="IE=7"

    content="IE=EmulateIE7"

    content="IE=8"

    content="IE=EmulateIE8"

    content="IE=9"

    content="IE=EmulateIE9"

    content="IE=edge"

回答by Amadiere

If you're working with a page in the Intranet Zone, you may find that IE9 no matter what you do, is going into IE7 Compat mode.

如果您正在处理 Intranet Zone 中的页面,您可能会发现无论您做什么,IE9 都会进入 IE7 兼容模式。

This is due to the setting within IE Compatibility settings which says that all Intranet sites should run in compatibility mode. You can untick this via a group policy (or just plain unticking it in IE), or you can set the following:

这是由于 IE 兼容性设置中的设置表明所有 Intranet 站点都应在兼容模式下运行。您可以通过组策略取消勾选(或在 IE 中直接取消勾选),或者您可以设置以下内容:

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

This works (as detailed in other answers), but may not initially appear so: it needs to come before the stylesheets are declared. If you don't, it is ignored.

这有效(如其他答案中详述),但最初可能不会出现:它需要在样式表声明之前出现。如果不这样做,它将被忽略。

回答by Peter Ruderman

I believe this will do the trick:

我相信这会解决问题:

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

回答by Erik Anderson

As suggested in this answerto a related question, "edge" mode can be set in the Web.Config file. This will make it apply to all HTML returned from the application without the need to insert it into individual pages:

正如此对相关问题的回答所建议的那样,可以在 Web.Config 文件中设置“边缘”模式。这将使其适用于从应用程序返回的所有 HTML,而无需将其插入单个页面:

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

This same step can also be accomplished by modifying the "HTTP Response Headers" using IIS Managerfor the IIS server, entire website, or specific applications.

同样的步骤也可以通过使用 IIS 管理器为 IIS 服务器、整个网站或特定应用程序修改“HTTP 响应头”来完成。

回答by Lance Anderson

The meta tag solution wasn't working for us but setting it in the response header did:

元标记解决方案对我们不起作用,但在响应标头中设置它可以:

header('X-UA-Compatible: IE=edge,chrome=1');

回答by Cloudkiller

Just a few more notes on this topic based on my recent experiences. The university I work for issues laptops with IE 8 set to compatibility mode for all Intranet Sites. I tried adding the meta tag to disable this mode for pages being served up by my site but IE consistently ignored this tag. As Lance mentioned in his post, adding a response header fixed this issue. This is how I set the header based on the HTML5 boilerplate method:

根据我最近的经验,就这个主题再做一些说明。我工作的大学将 IE 8 的笔记本电脑设置为所有 Intranet 站点的兼容模式。我尝试添加元标记来为我的网站提供的页面禁用此模式,但 IE 始终忽略此标记。正如 Lance 在他的帖子中提到的,添加响应头解决了这个问题。这是我根据 HTML5 样板方法设置标题的方式:

<IfModule mod_headers.c>
  Header set X-UA-Compatible "IE=edge,chrome=1"
  # mod_headers can't match by content-type, but we don't want to send this header on *everything*...
  <FilesMatch "\.(appcache|crx|css|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svg|svgz|ttf|vcf|webm|webp|woff|xml|xpi)$">
    Header unset X-UA-Compatible
  </FilesMatch>
</IfModule>

In order for this header to actually be sent, you have to make sure you have mod_headers turned on in Apache. If you want to make sure you have this mod turned on, put this in a page that can run php:

为了实际发送此标头,您必须确保在 Apache 中打开了 mod_headers。如果你想确保你打开了这个 mod,把它放在一个可以运行 php 的页面中:

<pre>
<?php
    print_r(apache_get_modules());
?>
</pre>

回答by rswank

IE8 defaults to standards mode for the intERnet and quirks mode for the intRAnet. The HTML meta tag is ignored if you have the doctype set to xhtml transitional. The solution is to add an HTTP header in code. This worked for us. Now our intranet site is forcing IE8 to render the app in standards mode.

IE8 默认为internet 的标准模式和intRAnet 的quirks 模式。如果您将 doctype 设置为 xhtml transitional,则 HTML 元标记将被忽略。解决方法是在代码中添加一个HTTP头。这对我们有用。现在我们的 Intranet 站点强制 IE8 以标准模式呈现应用程序。

Added to PageInit of the base page class (ASP.net C#):

添加到基页类(ASP.net C#)的PageInit:

Response.AddHeader("X-UA-Compatible", "IE=EmulateIE8");

reference: http://ilia.ws/archives/196-IE8-X-UA-Compatible-Rant.html

参考:http: //ilia.ws/archives/196-IE8-X-UA-Compatible-Rant.html

回答by Crouch

This is due to the setting within IE Compatibility settings which says that all Intranet sites should run in compatibility mode. You can untick this via a group policy (or just plain unticking it in IE), or you can set the following:

这是由于 IE 兼容性设置中的设置表明所有 Intranet 站点都应在兼容模式下运行。您可以通过组策略取消勾选(或在 IE 中直接取消勾选),或者您可以设置以下内容:

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

Apparently it is not possible to change the compatibility view settings as a group policy but it is something that can perhaps be changed in the registry, this meta tag works fine for me, I had to make the required attribute work as part of a html form, it worked in chrome and firefox but not IE.

显然不可能将兼容性视图设置更改为组策略,但它可能可以在注册表中更改,这个元标记对我来说很好用,我必须将所需的属性作为 html 表单的一部分工作,它适用于 chrome 和 firefox,但不适用于 IE。

Here is a nice visual of what browsers support each individual html 5 element.

这是浏览器支持每个单独的 html 5 元素的一个很好的视觉效果。

http://html5readiness.com/

http://html5readiness.com/

Notice the one common denominator Google Chrome, it supports everything. Hope this is of help

请注意 Google Chrome 的一个共同点,它支持一切。希望这有帮助

回答by technocrusaders.com

Insert as the very first item under the tag.

作为标签下的第一项插入。

This forces IE to render the page in the physical version of IE, and it ignores the Browser "Mode setting". This can be set in the developer tools, try changing it to a older version of IE to test, this should be ignored and the page should look exactly the same.

这会强制 IE 在 IE 的物理版本中呈现页面,并忽略浏览器的“模式设置”。这可以在开发者工具中设置,尝试将其更改为旧版本的 IE 进行测试,这应该被忽略并且页面应该看起来完全一样。