Javascript 如何修复 IE 9 中的文档模式重启

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

How to fix Document mode restart in IE 9

javascriptasp.netinternet-explorer-9doctype

提问by Amin Mousavi

I have a problem with opening my website in IE9. When I try to open my site I get this error in dev tools:

我在 IE9 中打开我的网站时遇到问题。当我尝试打开我的网站时,我在开发工具中收到此错误:

HTML1113: Document mode restart from Quirks to IE9 Standards

I googled and found an answer that suggested to use this:

我用谷歌搜索并找到了一个建议使用这个的答案:

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

or

或者

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

...but these do not work and I get the following message this time:

...但这些不起作用,这次我收到以下消息:

HTML1115: X-UA-Compatible META tag ('IE=Edge') ignored because document mode is already finalized.

What is my problem? I read several articles like IE's Compatibility Features for Site Developersby Microsoft and traced my site with Determining IE9's Document Modeflowchart and use all suggestions relating to !doctypeon these sites but no-one could solve my problem and my IE engine reset after the page opened.

我的问题是什么?我阅读了几篇文章,例如Microsoft为站点开发人员提供的 IE 兼容性功能,并使用确定 IE9 的文档模式流程图跟踪了我的站点,并在这些站点上使用了与!doctype相关的所有建议,但没有人可以解决我的问题,并且我的 IE 引擎在页面后重置打开。

I develop my site with ASP.NET 4 on Windows Server 2008. How can I fix this issue?

我在 Windows Server 2008 上使用 ASP.NET 4 开发我的网站。我该如何解决这个问题?

回答by Andrew Андрей Листочкин

One solution that should always work is to put your X-UA-Compatiblein HTTP headers. Also, your <!DOCTYPE>should be specified at the top of your HTML document (<!DOCTYPE html>is the easiest one).

应该始终有效的一种解决方案是将您X-UA-Compatible的 HTTP 标头放入。此外,您<!DOCTYPE>应该在 HTML 文档的顶部指定(<!DOCTYPE html>是最简单的)。

If you put your X-UA-Compatibledeclaration inside the metatag you can run into the following problems:

如果您将X-UA-Compatible声明放在meta标签内,您可能会遇到以下问题:

  1. X-UA-Compatibleis ignored unless it's present inside the first 4k of you page.If you put it somewhere in the bottom of your headsection (or in the body) move it to top. The best place for it is right after encoding and language declarations.
  2. X-UA-Compatibleis ignored if it's put inside IE conditional comments. For example:

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

    In this case you should remove conditional comments.

  3. Also, you shouldn't have any text before the doctypedeclaration. If you've got any HTML comments there, for example, the IE will switch to quirks mode.

  4. Finally, check if you're viewing this site from the intranet. By default Compatibility View is enabled for Intranet sites.

  1. X-UA-Compatible除非它出现在页面的前 4k 中,否则将被忽略。如果您将其放在head部分底部(或body)的某个位置,请将其移至顶部。它的最佳位置是在编码和语言声明之后。
  2. X-UA-Compatible如果放在 IE 条件注释中,则忽略它。例如:

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

    在这种情况下,您应该删除条件注释。

  3. 此外,您不应该在doctype声明之前有任何文本。例如,如果您有任何 HTML 注释,IE 将切换到 quirks 模式。

  4. 最后,检查您是否正在从 Intranet 查看此站点。默认情况下,对 Intranet 站点启用兼容性视图。

I suggest set X-UA-Compatibleheader for you page and then see if your site is still switching to quirks mode. In that case you should check your markup and try to fix any HTML validator errorsuntil it's back to Standards Mode.

我建议X-UA-Compatible为您的页面设置标题,然后查看您的网站是否仍在切换到怪癖模式。在这种情况下,您应该检查您的标记并尝试修复任何HTML 验证器错误,直到它回到标准模式。