如何修复IE 9中文档模式重新启动的问题

26

我在IE9中打开我的网站时遇到了问题。当我尝试打开我的网站时,在开发工具中出现了以下错误:

HTML1113: Document mode restart from Quirks to IE9 Standards

我谷歌搜索并找到一篇建议使用如下代码的答案:

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

...但这些方法都没有起作用,我得到了以下信息:

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

我的问题是什么?我阅读了一些文章,比如微软的IE兼容性功能(适用于网站开发人员),并使用确定IE9文档模式流程图来跟踪我的网站,并采用这些网站上与!doctype有关的所有建议,但没有一个能解决我的问题,而且我的IE引擎在页面打开后重置。

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


1
没有你的网站,就无法进行猜测了。请链接到您的网站,并编辑页面的HTML代码(不包括<body>)。 - Blender
1
我已经上传了测试文件这里。请使用用户名“test@afe.tt”和密码“123456”登录并检查此错误。谢谢。 - Amin Mousavi
1个回答

42

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

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

  1. X-UA-Compatible is ignored unless it's present inside the first 4k of you page. If you put it somewhere in the bottom of your head section (or in the body) move it to top. The best place for it is right after encoding and language declarations.
  2. X-UA-Compatible is 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 doctype declaration. 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.

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

将这个添加到头部真是救了我的一天...IE在每次重定向时也会抛出这个错误,比如302。那里没有HTML,所以它认为自己处于怪异模式,真是太愚蠢了... - Tomasz Struczyński
在我的情况下,我缺少了以下代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" > 这段代码应该放在页面开头。我只写了<html>。 - Davide Vosti
1
回复:#2,可以通过一些小技巧将x-ua-compatible放入条件语句中http://målform.no/blog/x-ua-optimal。没有这种技巧,`x-ua-compatible`无法在条件语句内运行,正如你所说,如果有条件语句在其之前也无法工作http://målform.no/blog/html5-boiler-plate-prevents-x-ua-compatible。回复:#3,在doctype之前使用条件注释是可以的http://målform.no/blog/no-condition-comments。这些不是我的文章,但我的测试支持它们。 - Chad von Nau
1
@Andrew Андрей Листочкин,我不知道为什么在 <!DOCTYPE html> 之前我无法添加任何注释,但当我改变了我的 HTML 注释位置后,它就像魔法般地奏效了。感谢您的解决方案。 - HddnTHA

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接