如何强制 Internet Explorer 以标准模式而不是怪异模式呈现?
我正在编写一个在 IE7 标准模式和 IE8 标准模式下运行良好的前端。
当我启动 Internet Explorer 并加载页面时,IE7 和 IE8 都会直接进入 Quirks 模式。如何强制 IE7 和 IE8 始终以标准模式加载页面?
到目前为止我还没有添加特殊的元标签。
感谢您帮助我
编辑:我的文档类型和头部目前如下所示:
<!DOCTYPE html>
<html lang="de">
<head>
<title>...</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
<script src="js/html5.js"></script>
(...)
</head>
I am coding a Frontend which works well in IE7 Standards Mode and IE8 Standards Mode.
When I start up Internet Explorer and load the page both IE7 and IE8 go to Quirks Mode directly. How can I force both IE7 and IE8 to always load the page in Standards Mode?
I have no special meta tags added so far.
Thanks for helping me out
Edit: My doctype and head looks as follows at the moment:
<!DOCTYPE html>
<html lang="de">
<head>
<title>...</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
<script src="js/html5.js"></script>
(...)
</head>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是绝对确定的方法:
原因:
每当 IE 遇到任何冲突时,它都会返回“IE 7 标准模式”,忽略 x-ua 兼容。
(我知道这是一个非常古老的问题的答案,但我自己也一直在努力解决这个问题,上面的方案是正确的答案。它一直有效,每次)
This is the way to be absolutely certain :
Reason :
Whenever IE meets anything that conflicts, it turns back to "IE 7 standards mode", ignoring the
x-ua-compatible
.(I know this is an answer to a very old question, but I have struggled with this myself, and above scheme is the correct answer. It works all the way, everytime)
可悲的是,他们希望我们使用标签来让他们的浏览器知道该怎么做。看看这个文档,它告诉我们使用:
应该可以。
Sadly, they want us to use a tag to let their browser know what to do. Look at this documentation, it tell us to use:
and it should do.
在页面开头使用 html5 文档类型。
强制 IE 使用最新的渲染模式
如果您的目标浏览器是 ie8,请检查您的兼容设置
在 IE8 中
我详细介绍了此内容
Using html5 doctype at the beginning of the page.
<!DOCTYPE html>
Force IE to use the latest render mode
<meta http-equiv="X-UA-Compatible" content="IE=edge">
If your target browser is ie8, then check your compatible settings
in IE8
I blog this in details
添加正确的文档类型声明并避免 XML 序言应该足以避免怪异模式。
Adding the correct doctype declaration and avoiding the XML prolog should be enough to avoid quirks mode.
我知道这个问题是两年前提出的,但还没有人提到过。
最好的方法是使用 http 标头
将元标记添加到标头并不总是有效,因为 IE 可能在读取之前就已经确定了模式。确保 IE 始终使用标准模式的最佳方法是使用自定义 http 标头。
标头:
例如,在 .NET 应用程序中,您可以将其放入 web.config 文件中。
I know this question was asked over 2 years ago but no one has mentioned this yet.
The best method is to use a http header
Adding the meta tag to the head doesn't always work because IE might have determined the mode before it's read. The best way to make sure IE always uses standards mode is to use a custom http header.
Header:
For example in a .NET application you could put this in the web.config file.
HTML5 Doctype 可能会导致您在使用旧版浏览器时出现问题。它也可能与 HTML5 shiv 相关的一些时髦的东西有关。
您可以尝试切换到一种 XHTML 文档类型并相应地更改您的标记,至少暂时如此。这可能会让您缩小问题范围。
当这些 IE 切换到怪异模式时,您的设计是否会被破坏?如果是您的 CSS 导致内容显示异常,那么可能值得对 CSS 进行处理,以便即使浏览器切换模式,网站看起来也一样。
It's possible that the HTML5 Doctype is causing you problems with those older browsers. It could also be down to something funky related to the HTML5 shiv.
You could try switching to one of the XHTML doctypes and changing your markup accordingly, at least temporarily. This might allow you to narrow the problem down.
Is your design breaking when those IEs switch to quirks mode? If it's your CSS causing things to display strangely, it might be worth working on the CSS so the site looks the same even when the browsers switch modes.