令人沮丧:无法强制 IE 8 进入“兼容性视图”!
我有两个截然不同的网站。 两者在“Internet Explorer 8”浏览器模式下显示时出现不同的错误!
单击地址栏旁边的“兼容性视图”按钮时,这两个网站看起来都很棒。 当我后来使用内置的“开发者工具”查看“浏览器模式”和“文档节点”时,我还注意到“浏览器模式”是“IE8兼容视图”,“文档模式”是“IE7标准” ”。 正如我所期望的那样。
然后我想强制“Internet Explore 8”进入“浏览器模式”:“IE8 兼容视图”,这样我的用户就不必单击地址栏旁边的“兼容性视图”按钮来获取他们真正需要的内容查看。
我能想到的唯一方法是在标题内的标题下方插入元标记,如下所示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Test</title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<link ... />
<script ...></script>
</head>
<body>
...
</body>
</html>
然后我重新加载网站,地址栏旁边的“兼容性视图”按钮消失。 正如预期的那样。 当我后来使用内置的“开发者工具”查看“浏览器模式”和“文档节点”时,我突然看到了一些我真正没想到的东西。 我期望“浏览器模式”为“IE8兼容视图”,“文档节点”为“IE7标准”,但“浏览器模式”为“IE8”,“文档模式”为“IE7标准”,并且与在“Internet Explorer 8”浏览器模式下查看相比,网站突然出现一组新错误!
非常令人沮丧的是,为什么我不能强制使用“IE8 Compat view”浏览器模式而不是“Internet explore 7”或“Internet explore 8”浏览器模式?
I've got two very different websites. Both of them have different errors when displayed in the "Internet explorer 8" browser mode!
When clicking the "Compatibility view" button next to the address bar both of the sites look great. When I afterwards look at the "Browser mode" and "Document node" by using the built-in "Developer tools", I also notice the "Browser mode" is "IE8 Compat view" and the "Document mode" is "IE7 Standards". Just as I expect them to be.
Then I want to force "Internet Explore 8" into the "Browser mode" : " IE8 Compat view", so that my users won't have to click the "Compatibility view" button next to the address bar to get what they really need to see.
The only way I can think of doing this is by inserting a metatag below the title inside the header like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Test</title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<link ... />
<script ...></script>
</head>
<body>
...
</body>
</html>
Then i reload the website and the "Compatibility view" button next to the address bar disapears. Just as expected. When I afterwards look at the "Browser mode" and "Document node" by using the built-in "Developer tools", I suddenly see something I really did NOT expect. I expected the "Browser mode" to be "IE8 Compat view" and the "Document node" to be "IE7 Standards", but the "Browser mode" is "IE8" and the "Document mode" is "IE7 Standards" and the websites suddenly have a new set of errors compared to when viewed in "Internet explorer 8" browser mode!
It is very frustrating why can't I force the "IE8 Compat view" browser mode instead of the "Internet explore 7" or "Internet explore 8" browser modes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
至 引用IEBlog:
http://msdn.microsoft 上有更多详细信息.com/en-us/library/dd565624(VS.85).aspx。
正如您可以清楚地看到的,无论如何您都无法影响所有这些事情:当您告诉浏览器像 IE7 一样运行时,它已经像 IE8 一样运行了。
也许真正的问题是:为什么浏览器模式对您来说如此重要?文档模式是您应该最关心的 - 浏览器模式改变的所有内容(就渲染而言)所关心的内容涉及排除/包含但版本检查的内容,并且用户无论如何都不会查看开发人员工具,因此他们不会关心。
与其浪费大量时间让它看起来像开发人员工具中的纯兼容模式,不如去确保用户代理字符串检查和条件注释使其能够使 IE7 和 IE8 获得相同的材料来使用,然后保留 EmulateIE7。
编辑:
问题是您的版本检查,正如我在下面所承诺的,我将告诉您问题出在哪里。
如果您使用开发者工具调试菜单放置脚本,您可以深入了解,当浏览器报告自己为 IE7 或 IE8 时,get_x_position 的执行路径有所不同:对于 IE7,
is_ie5up
设置为 true模式,对于 IE8 模式为 false。 这会导致返回非常不同的值。此时,我们必须回到设置该变量的位置:
如您所见,这取决于
is_ie6up
的值,所以让我们看看周围的代码......你发现缺陷了吗(提示:比较该片段的第 2 行和第 4 行)?
没错:除非浏览器恰好是 IE6 或 IE7,否则
is_ie6up
不会设置为 true。 正确的行当然应该是……但是等等。 这也不好,因为代码片段的第 3 行将
is_ie7up
更改为仅当浏览器恰好是 IE7 时才为 true! 因此,您需要删除is_ie7up
的覆盖,并修复is_ie6up
的设置。我的猜测是,您在其他网站上也遇到了完全相同的问题:您以几乎相同的方式搞乱了浏览器检查。
To quote the IEBlog:
It's detailed a bit more on http://msdn.microsoft.com/en-us/library/dd565624(VS.85).aspx.
As you can clearly see, you wouldn't be able to affect all of these things anyway: by the time you tell the browser to act like IE7, it's already acting as IE8.
Perhaps the real question is: Why does it matter that much to you what the browser mode is? The document mode is what you should be most concerned with - everything the browser mode changes as far as the rendering is concerned relate to stuff that is excluded/included but version checking, and users aren't going to look in the developer tools anyway, so they won't care.
Instead of wasting a lot of time getting it to look like pure compatibility mode in the developer tools, you should rather go and make sure that user agent string checking and conditional comments make it so that IE7 and IE8 get the same material to work with, and then leave the EmulateIE7 in.
EDIT:
The problem is your version checks, and as I promised below, I'm going to tell you where the problem is.
If you use the developer tools to debug the menu placement script, you can dig down and see that the execution path for get_x_position differs when the browser reports itself as IE7 or IE8:
is_ie5up
is set to true for IE7 mode, and false for IE8 mode. This results in very different values being returned.At this point, we must go back to where this variable is set:
As you can see, this depends on the value of
is_ie6up
, so let's have a look at the surrounding code......do you spot the flaw (Hint: compare lines 2 and 4 of that snippet)?
That's right:
is_ie6up
is not set to true unless the browser is exactly IE6 or IE7. The proper line should of course read...but wait. That's no good either, because line 3 of the snippet changes
is_ie7up
to only be true if the browser is exactly IE7! So, you need to delete the overwriting ofis_ie7up
, and fix the setting ofis_ie6up
.My guess is that you have the EXACT same problem on the other site: you've messed up the browser checks in much the same way.
您已正确设置元标记,但 IE8 似乎使用以前的渲染模式,直到您重新启动浏览器。
要了解用户将看到的内容:
文档模式
,然后查看标记为(页面默认)
的值。You have set the meta tag correctly, but IE8 appears to use the previous rendering mode until you restart the browser.
To tell what your users are going to see:
Document Mode
in the developer toolbar and see which value is marked(Page Default)
.xmlns="http://www.w3.org/1999/xhtml" 属性正在取消元标记。 将元标记移至 html 标记上方。 是的,没错,就在 html 标签上方。 然后它将在 javascript 运行之前执行 emulateIE7。 我在 IE7、IE8 和 Firefox 中对此进行了测试。
The xmlns="http://www.w3.org/1999/xhtml" attribute is cancelling out the meta tag. Move the meta tag above the html tag. Yep, that's right, above the html tag. Then it will execute the emulateIE7 before the javascript runs. I tested this in IE7, IE8 and Firefox.
在我的特殊情况下,我的网站无法在兼容视图中正确呈现。 我终于了解到浏览器模式会影响用户代理字符串。 我的网站样式规则基于用户代理,因此某些样式根本无法在兼容视图中应用。
我使用的是
这样以后我可以使用 css 属性选择器,就像
我通过添加解决的那样:(
不关心真正的 IE7,因为无论如何都不支持真正的 IE7)
根据我的经验,开发人员无法强制 IE8 从“浏览器模式: IE8 兼容视图”进入“浏览器模式:IE8”。 再说一遍,我谈论的是 BrowserModes 而不是 DocumentModes(可以通过元标记、响应标头等控制)。
In my particular case my site would not render properly in Compat View. I finally learned that Browser Mode affects the User Agent string. My site style rules were based on User Agent so some styles were simply not getting applied in Compat view.
I was using
so that later I could use css attribute selectors like
I solved by adding:
(not caring about true IE7 as true IE7 was not supported anyway)
In my experience there is nothing a developer can do to force IE8 from "Browser Mode: IE8 Compat View" into "Browser Mode: IE8". Again, I am are talking about BrowserModes NOT DocumentModes (which can be controlled by meta tags, response headers, etc).
问题不是您使用了错误的文档类型吗?
也许:
有关详细信息,请参阅 http://htmlhelp.com/tools/validator/doctype.html 。
Isn't the problem that you're using the wrong document type?
Maybe:
For more info, see http://htmlhelp.com/tools/validator/doctype.html.
我正在转换 XML 文档,因此无法正确设置 DOCTYPE。 我没有将其移动到 XML 无效的
之上,而是将其放在标头中。
在 PHP 中:
I was transforming an XML document so I couldn't set the DOCTYPE properly. Instead of moving above
<html>
, which is XML-invalid, I simply put it in a header.In PHP:
使用 asp 经典站点的 HML5 Boilerplate 强制 IE8 进入文档模式 IE8 标准时遇到问题。 将这个问题和其他问题的答案拼凑在一起,在
声明上方添加此代码似乎已经解决了问题,并强制文档模式从 IE7 回到 IE8。<%= response.AddHeader("X-UA-Compatible", "IE=edge") %>
Had a problem forcing IE8 into Document Mode IE8 Standards using the HML5 Boilerplate for an asp classic site. Piecing together answers from this and other questions, adding this code ABOVE the
<doctype>
declaration seems to have resolved the problem and forced Document Mode from IE7 back to IE8.<%= response.AddHeader("X-UA-Compatible", "IE=edge") %>
更新站点
如果您的页面包含 ASP.NET Ajax 内容,您可能需要使用此http://support 。 microsoft.com/kb/2600088
If your page contains ASP.NET Ajax stuff, you may need to update the site with this
http://support.microsoft.com/kb/2600088