Html IE8 标准模式元标记
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4987439/
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
IE8 standards mode meta tag
提问by davidsleeps
A web application we have for an organisation that is officially upgrading its standard browser from IE6 to IE8 (queue celebrations), we've set all our DOCTYPEs to be <!DOCTYPE html>
(as well as fixed other html code) and I thought that in IE8 this would cause the page to be rendered in IE8 Standards Mode. However, it is still shown in IE7 Standards mode.
我们为一个正式将其标准浏览器从 IE6 升级到 IE8(队列庆祝)的组织的 Web 应用程序,我们已将所有 DOCTYPE 设置为<!DOCTYPE html>
(以及固定的其他 html 代码),我认为在 IE8 中这将导致页面在 IE8 标准模式下呈现。但是,它仍然以 IE7 标准模式显示。
I've added the <meta http-equiv="X-UA-Compatible" content="IE=8">
into the <head>
section and it still fails to default to IE8 Standards mode. I'm presuming at this stage that there must be a setting (perhaps Group Policy etc) that is forcing the mode.
我已经添加了<meta http-equiv="X-UA-Compatible" content="IE=8">
进入<head>
部分,它仍然无法默认为IE8标准模式。我假设在这个阶段必须有一个强制模式的设置(可能是组策略等)。
After reading a hack on an MSDN forum that if you put the meta tag before the <html>
tag, it correctly displays as IE8 Standards mode, and this worked for me. Is there another way to do this? It just looks terrible seeing the meta tag there...
在阅读了 MSDN 论坛上的 hack 之后,如果您将元标记放在标记之前<html>
,它会正确显示为 IE8 标准模式,这对我有用。有没有另一种方法可以做到这一点?看到那里的元标签看起来很糟糕......
Here's roughly how each page is made up:
每个页面的组成大致如下:
<!DOCTYPE html>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page Title</title>
</head>
<body>
</body>
</html>
回答by thirtydot
You could set X-UA-Compatible
as a HTTP response header, instead of as a meta tag.
您可以设置X-UA-Compatible
为 HTTP 响应标头,而不是元标记。
This is a much cleaner solution than placing it above the <html>
tag.
这是一个比将它放在<html>
标签上方更干净的解决方案。
A confusinguseful blog post concerning X-UA-Compatible
and its many intricacies:
一篇令人困惑的有用博客文章,涉及X-UA-Compatible
及其许多错综复杂:
http://farukat.es/journal/2009/05/245-ie8-and-the-x-ua-compatible-situation
http://farukat.es/journal/2009/05/245-ie8-and-the-x-ua-compatible-situation
回答by Pekka
Two possibilities:
两种可能:
The
meta
tag definitely belongs into the<head>
section of the document.If this is in an Intranet, this may be IE's "Smart default" kicking in. Yes, there is such a thing as smart defaults. See here. Because if you're in an Intranet, IE8 will automatically go into IE7 compatibility mode so as not to break the many corporate apps that rely on IE7. Makes sense, right? Right?
该
meta
标签绝对属于成<head>
文档的部分。如果这是在 Intranet 中,这可能是 IE 的“智能默认值”发挥作用。是的,有智能默认值这样的东西。见这里。因为如果你在内网,IE8会自动进入IE7兼容模式,以免破坏很多依赖IE7的企业应用。有道理吧?对?