Html 强制 Internet Explorer 9 使用标准文档模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10975107/
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
Forcing Internet Explorer 9 to use standards document mode
提问by MaxRecursion
How can I force Internet Explorer 9 to use standards document mode? I built a website and I'm finding that IE9 uses quirks mode to render the website pages. But I want to use standards mode for rendering.
如何强制 Internet Explorer 9 使用标准文档模式?我建立了一个网站,我发现 IE9 使用 quirks 模式来呈现网站页面。但我想使用标准模式进行渲染。
回答by Jukka K. Korpela
<!doctype html>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
This makes each version of IE use its standard mode, so IE 9 will use IE 9 standards mode. (If instead you wanted newer versions of IE to alsospecifically use IE 9 standards mode, you would replace Edge
by 9
. But it is difficult to see why you would want that.)
这使得每个版本的 IE 都使用其标准模式,因此 IE 9 将使用 IE 9 标准模式。(相反,如果您希望较新版本的 IE也专门使用 IE 9 标准模式,则可以替换Edge
为9
。但很难理解为什么要这样做。)
For explanations, see http://hsivonen.iki.fi/doctype/#ie8(it looks rather messy, but that's because IE is messy in its behaviors).
有关解释,请参阅http://hsivonen.iki.fi/doctype/#ie8(它看起来相当混乱,但那是因为 IE 的行为混乱)。
回答by Ty Petrice
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
The meta tag must be the first tag after the head tag or it will not work.
元标记必须是头标记之后的第一个标记,否则将不起作用。
回答by David Esquivel
There is something very important about this thread that has been touched on but not fully explained. The HTML approach (adding a meta tag in the head) only works consistently on raw HTML or very basic server pages. My site is a very complex server-driven site with master pages, themeing and a lot of third party controls, etc. What I found was that some of these controls were programmatically adding their own tags to the final HTML which were being pushed to the browser at the beginning of the head tag. This effectively rendered the HTML meta tags useless.
关于这个线程有一些非常重要的东西已经被触及但没有完全解释。HTML 方法(在头部添加元标记)仅适用于原始 HTML 或非常基本的服务器页面。我的站点是一个非常复杂的服务器驱动站点,包含母版页、主题和许多第三方控件等。我发现其中一些控件以编程方式将自己的标签添加到最终的 HTML 中,这些标签被推送到浏览器在 head 标签的开头。这有效地使 HTML 元标记无用。
Well, if you can't beat them, join them. The only solution that worked for me is to do exactly the same thing in the pre-render event of my master pages as such:
好吧,如果你不能打败他们,那就加入他们吧。唯一对我有用的解决方案是在我的母版页的预渲染事件中做完全相同的事情:
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Dim MetaTag As HtmlMeta = New HtmlMeta()
MetaTag.Attributes("http-equiv") = "Content-Type"
MetaTag.Attributes("content") = "text/html; charset=utf-8;"
Page.Header.Controls.AddAt(0, MetaTag)
MetaTag = New HtmlMeta()
MetaTag.Attributes("http-equiv") = "X-UA-Compatible"
MetaTag.Attributes("content") = "IE=9,chrome=1"
Page.Header.Controls.AddAt(0, MetaTag)
End Sub
This is VB.NET but the same approach would work for any server-side technology. As long as you make sure it's the last thing that gets done right before the page is rendered.
这是 VB.NET,但同样的方法适用于任何服务器端技术。只要您确保这是在呈现页面之前完成的最后一件事。
回答by SuperDuck
To prevent quirks mode, define a 'doctype' like :
为了防止怪癖模式,定义一个“doctype”,如:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
To make IE render the page in IE9 document mode :
要使 IE 在 IE9 文档模式下呈现页面:
<meta http-equiv="x-ua-compatible" content="IE=9">
Please note that "IE=edge"
will make IE render the page with the most recent document mode, rather than IE9 document mode.
请注意,"IE=edge"
这将使 IE 以最新的文档模式呈现页面,而不是 IE9 文档模式。
回答by inancsevinc
put a doctype as the first line of your html document
将 doctype 作为 html 文档的第一行
<!DOCTYPE html>
<!DOCTYPE html>
you can find detailed explanation about internet explorer document compatibility here: Defining Document Compatibility
您可以在此处找到有关 Internet Explorer 文档兼容性的详细说明:定义文档兼容性
回答by eoinDeveloper
Make sure you take into account that adding this tag,
确保您考虑到添加此标签,
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
may only allow compatibility with the latest versions. It all depends on your libraries
可能只允许与最新版本兼容。这一切都取决于你的图书馆
回答by Madhu Sareen
I tried with an alternate method:
我尝试了另一种方法:
Hit F12 key Then, at right hand side in the drop down menu, select internet explorer version 9.
按 F12 键然后,在下拉菜单的右侧,选择 Internet Explorer 版本 9。
That's it and it worked for me.
就是这样,它对我有用。
回答by KarthikaSrinivasan
I have faced issue like my main page index.jsp contains the below line but eventhough rendering was not proper in IE. Found the issue and I have added the code in all the files which I included in index.jsp. Hurray! it worked.
我遇到了问题,比如我的主页 index.jsp 包含以下行,但即使在 IE 中渲染不正确。找到了问题,我在 index.jsp 中包含的所有文件中添加了代码。欢呼!有效。
So You need to add below code in all the files which you include into the page otherwise it wont work.
因此,您需要在包含到页面中的所有文件中添加以下代码,否则它将无法工作。
<!doctype html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
</head>
回答by Moin Zaman
Make sure you use the right doctype.
确保使用正确的文档类型。
eg.
例如。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
or just
要不就
<!doctype html>
<!doctype html>
and also readand understand how compatibility modes and developer toolbar for IE work and set modes for IE:
并阅读并了解 IE 的兼容模式和开发人员工具栏如何工作以及为 IE 设置模式: