Html 无论我尝试什么,IE9 始终使用 IE7 标准文档模式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12837869/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:19:21  来源:igfitidea点击:

IE9 constantly using IE7 standards document mode no matter what I try

htmlinternet-explorer-9

提问by Alan Shortis

This is driving me insane.

这让我发疯。

No matter what I try, Internet Explorer is switching to IE7 Standards Document Mode. I have tried stripping my code back to nothing to try and get it to behave, using HTML5 boilet plate AND HTML5 reset (whose own site goes into Quirks Mode).

无论我尝试什么,Internet Explorer 都会切换到 IE7 标准文档模式。我曾尝试将我的代码剥离回零以尝试使其行为,使用 HTML5 锅板和 HTML5 重置(其自己的网站进入怪癖模式)。

I have also added the meta tag that is supposed to force IE to it's latest version no matter what, but all that has done is made my mark-up invalid according to W3C.

我还添加了元标记,无论如何都应该强制 IE 使用它的最新版本,但是根据 W3C,所做的一切都使我的标记无效。

This is what I have; what am I missing?

这就是我所拥有的;我错过了什么?

<!doctype html>

<!--[if IE 7 ]> <html class="ie7> <![endif]-->
<!--[if IE 8 ]> <html class="ie8> <![endif]-->
<!--[if gt IE 8]><!--><html><!--<![endif]-->

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title></title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <p>Test text</p>        
</body>
</html>

EDIT

编辑

I have a solution found via a suggestion below. The suggestion didn't work, but it did lead me to an answer. This might not be 100% suitable for everyone since it imposes a class on the bodytag rather than html, but it works for me and seems to work for IE.

我通过以下建议找到了解决方案。该建议没有奏效,但它确实让我找到了答案。这可能不是 100% 适合所有人,因为它在body标签上强加了一个类而不是html,但它对我有用,而且似乎对 IE 也有用。

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="css/style.css">
</head>
<!--[if IE 7 ]> <body class="ie7> <![endif]-->
<!--[if IE 8 ]> <body class="ie8> <![endif]-->
<!--[if gt IE 8]><!--><body><!--<![endif]-->
<p>Test text</p>        
</body>
</html>

采纳答案by Alan Shortis

I have a solution found via an earlier suggestion. The suggestion didn't work, but it did lead me to an answer. This might not be 100% suitable for everyone since it imposes a class on the bodytag rather than html, but it works for me and seems to work for IE.

我通过较早的建议找到了解决方案。该建议没有奏效,但它确实让我找到了答案。这可能不是 100% 适合所有人,因为它在body标签上强加了一个类而不是html,但它对我有用,而且似乎对 IE 也有用。

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="css/style.css">
</head>
<!--[if IE 7 ]> <body class="ie7> <![endif]-->
<!--[if IE 8 ]> <body class="ie8> <![endif]-->
<!--[if gt IE 8]><!--><body><!--<![endif]-->
<p>Test text</p>        
</body>
</html>

EDIT

编辑

I have actually stopped using the above and now add my IE specific classes to the htmlelement, as suggested in HTML5BP.

我实际上已经停止使用上述内容,现在html按照 HTML5BP 中的建议将我的 IE 特定类添加到元素中。

Also note that you may want to remove chrome=1from the meta tag as Chrome Frame is being killed off soon. No harm in keeping it though for those rare cases where someone is still using it though.

另请注意,您可能希望chrome=1从元标记中删除,因为 Chrome Frame 即将被淘汰。不过,对于那些仍在使用它的罕见情况,保留它并没有什么坏处。

Another thing to check which I don't think has been mentioned is the status of what is probably the most irritating setting in IE - 'Display intranet sites in Compatibility View'. If you run a testing server with a name like http://mytestserver:8888IE will think it's an intranet site and switch modes regardless of what you do in your document head.

另一件我认为没有提到的要检查的事情是可能是 IE 中最令人恼火的设置的状态 - “在兼容性视图中显示 Intranet 站点”。如果您运行名为http://mytestserver:8888IE 之类的测试服务器,则无论您在文档头中做什么,它都会认为它是一个 Intranet 站点并切换模式。

This setting is enabled in my company's group policy as our ancient sharepoint intranet actually relies on it. Great for the old crap, but terrible for the new stuff which is actually going to adhere to standards.

我公司的组策略中启用了此设置,因为我们古老的 Sharepoint Intranet 实际上依赖于它。对旧的废话很好,但对于实际上要遵守标准的新东西来说很糟糕。

Switch that f***er off in Tools > Compatibility View Settingsand be prepared to switch to it manually if you have any legacy sites.

Tools > Compatibility View Settings如果您有任何遗留站点,请关闭该功能并准备手动切换到它。

回答by Anoop

from this thread

这个线程

The X-UA-Compatible meta tag must appear straight after the title in the element. No other meta tags, css links and js scripts calls can be placed before it.

X-UA-Compatible 元标记必须直接出现在元素中的标题之后。在它之前不能放置其他元标记、css 链接和 js 脚本调用。

回答by st3inn

Sometimes IE behaves extra badly on intranet sites, forcing them into compatibility mode regardless of the <meta>line in the head. However, you can make the server send a header to brute-force IE to behave by adding the following to the web config:

有时 IE 在 Intranet 站点上表现得特别糟糕,迫使它们进入兼容模式而不管<meta>头部的行。但是,您可以通过将以下内容添加到 Web 配置中,使服务器向暴力 IE 发送标头以使其行为:

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-UA-Compatible" value="IE=Edge" />
      </customHeaders>
    </httpProtocol>
</system.webServer>

回答by dorian

Keep the

保持

<!doctype html>

to be the first line of the page source, and the X-UA-Compatible meta tag must be tilte tag's adjacent next sibling.

作为页面源的第一行,并且 X-UA-Compatible 元标记必须是倾斜标记的相邻下一个兄弟。

<meta charset="utf-8">
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

回答by Semra

I was also having this issue with ie10 forcing IE7 standards mode for sites on localhost. Adding/using a virtualhost including a dot in its name (local.x) solved the issue.

我也遇到了这个问题,ie10 强制本地主机上的站点使用 IE7 标准模式。添加/使用名称中包含一个点的虚拟主机 (local.x) 解决了该问题。

回答by Shawn

I've used the following to fix this problem when IE8 was rendering in IE7 Standards document mode despite all else I tried. Add this just before the doctype declaration:

尽管我尝试了所有其他方法,但当 IE8 在 IE7 标准文档模式下呈现时,我已经使用以下方法解决了这个问题。在 doctype 声明之前添加:

<!--[if IE ]><![endif]-->

So the resulting HTML would look something like this:

所以生成的 HTML 看起来像这样:

<!--[if IE ]><![endif]-->
<!doctype html>
<!--[if IE 7]><html class="lt-ie8"><![endif]-->
<!--[if IE 8]><html class="lt-ie9"><![endif]-->
<!--[if gt IE 8]><!--><html><!--<![endif]-->
<head>
    <title>Page title here</title>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>

Someone else will have to comment on whythis seems to work--it is a mystery to me.

其他人将不得不评论为什么这似乎有效——这对我来说是个谜。

回答by Chad Miller

The link that Stuart posted worked for me as it related to the local website being set for compatibility mode. Once I removed the intranet website from the compatibility mode list, then the page went to the proper IE=9 mode according to the meta tag.

Stuart 发布的链接对我有用,因为它与设置为兼容模式的本地网站有关。一旦我从兼容模式列表中删除了内网网站,页面就会根据元标记转到正确的 IE=9 模式。