强制Internet Explorer 9使用标准文档模式

时间:2021-08-09 17:44:39

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.

如何强制internetexplorer9使用标准文档模式?我建立了一个网站,我发现IE9使用怪癖模式来呈现网站页面。但是我想用标准模式渲染。

8 个解决方案

#1


124  

 <!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 also specifically use IE 9 standards mode, you would replace Edge by 9. But it is difficult to see why you would want that.)

这使得每个版本的IE都使用它的标准模式,因此ie9将使用ie9标准模式。(如果你想要更新版本的IE也特别使用ie9标准模式,你可以用9替换Edge。但很难看出你为什么想要那样。

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在行为上很乱)。

#2


17  

<!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.

元标记必须是头标记之后的第一个标记,否则它将不起作用。

#3


10  

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方法(在head中添加一个元标记)只在原始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但是同样的方法也适用于任何服务器端技术。只要确保它是在呈现页面之前完成的最后一件事。

#4


6  

put a doctype as the first line of your html document

将doctype作为html文档的第一行

<!DOCTYPE html>

you can find detailed explanation about internet explorer document compatibility here: Defining Document Compatibility

您可以在这里找到有关internet explorer文档兼容性的详细解释:定义文档兼容性

#5


5  

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 :

在IE9文档模式下,使IE呈现页面:

<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文档模式。

#6


3  

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

可能只允许与最新版本兼容。这完全取决于你的库

#7


0  

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.

对我来说就是这样。

#8


0  

Make sure you use the right doctype.

确保使用正确的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 read and understand how compatibility modes and developer toolbar for IE work and set modes for IE:

并阅读和理解IE的兼容性模式和开发工具栏以及IE的设置模式:

#1


124  

 <!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 also specifically use IE 9 standards mode, you would replace Edge by 9. But it is difficult to see why you would want that.)

这使得每个版本的IE都使用它的标准模式,因此ie9将使用ie9标准模式。(如果你想要更新版本的IE也特别使用ie9标准模式,你可以用9替换Edge。但很难看出你为什么想要那样。

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在行为上很乱)。

#2


17  

<!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.

元标记必须是头标记之后的第一个标记,否则它将不起作用。

#3


10  

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方法(在head中添加一个元标记)只在原始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但是同样的方法也适用于任何服务器端技术。只要确保它是在呈现页面之前完成的最后一件事。

#4


6  

put a doctype as the first line of your html document

将doctype作为html文档的第一行

<!DOCTYPE html>

you can find detailed explanation about internet explorer document compatibility here: Defining Document Compatibility

您可以在这里找到有关internet explorer文档兼容性的详细解释:定义文档兼容性

#5


5  

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 :

在IE9文档模式下,使IE呈现页面:

<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文档模式。

#6


3  

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

可能只允许与最新版本兼容。这完全取决于你的库

#7


0  

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.

对我来说就是这样。

#8


0  

Make sure you use the right doctype.

确保使用正确的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 read and understand how compatibility modes and developer toolbar for IE work and set modes for IE:

并阅读和理解IE的兼容性模式和开发工具栏以及IE的设置模式: