令人沮丧:无法强制 IE 8 进入“兼容性视图”!

发布于 2024-07-30 11:41:29 字数 1243 浏览 8 评论 0原文

我有两个截然不同的网站。 两者在“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

巴黎夜雨 2024-08-06 11:41:29

引用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。 这会导致返回非常不同的值。

此时,我们必须回到设置该变量的位置:

var is_ie5up    = (is_ie6up || (is_ie  && !is_ie3 && !is_ie4));

如您所见,这取决于 is_ie6up 的值,所以让我们看看周围的代码

var is_ie8up    = (is_ie8   ||  is_ie9up);
var is_ie7up    = (is_ie7   ||  is_ie8up);
var is_ie7up    = (is_ie7);
var is_ie6up    = (is_ie6   || is_ie7);
var is_ie5up    = (is_ie6up || (is_ie  && !is_ie3 && !is_ie4));
var is_ie5_5up  = (is_ie6up || (is_ie && !is_ie3 && !is_ie4 && !is_ie5));

......你发现缺陷了吗(提示:比较该片段的第 2 行和第 4 行)?

没错:除非浏览器恰好是 IE6 或 IE7,否则 is_ie6up 不会设置为 true。 正确的行当然应该是

var is_ie6up    = (is_ie6   || is_ie7up);

……但是等等。 这也不好,因为代码片段的第 3 行将 is_ie7up 更改为仅当浏览器恰好是 IE7 时才为 true! 因此,您需要删除is_ie7up的覆盖,并修复is_ie6up的设置。

我的猜测是,您在其他网站上也遇到了完全相同的问题:您以几乎相同的方式搞乱了浏览器检查。

To quote the IEBlog:

“Browser Mode” affects the user agent
string, version vector used when
evaluating conditional comments, and
the rendering mode.

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:

var is_ie5up    = (is_ie6up || (is_ie  && !is_ie3 && !is_ie4));

As you can see, this depends on the value of is_ie6up, so let's have a look at the surrounding code...

var is_ie8up    = (is_ie8   ||  is_ie9up);
var is_ie7up    = (is_ie7   ||  is_ie8up);
var is_ie7up    = (is_ie7);
var is_ie6up    = (is_ie6   || is_ie7);
var is_ie5up    = (is_ie6up || (is_ie  && !is_ie3 && !is_ie4));
var is_ie5_5up  = (is_ie6up || (is_ie && !is_ie3 && !is_ie4 && !is_ie5));

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

var is_ie6up    = (is_ie6   || is_ie7up);

...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 of is_ie7up, and fix the setting of is_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.

肤浅与狂妄 2024-08-06 11:41:29

您已正确设置元标记,但 IE8 似乎使用以前的渲染模式,直到您重新启动浏览器。

要了解用户将看到的内容:

  1. 单击开发人员工具栏中的文档模式,然后查看标记为(页面默认) 的值。
  2. 重新启动 IE8 并查看文档 - IE 现在应该使用默认页面。

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:

  1. Click on the Document Mode in the developer toolbar and see which value is marked (Page Default).
  2. Restart IE8 and view your document - IE should now use the page default.
£噩梦荏苒 2024-08-06 11:41:29

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.

蝶舞 2024-08-06 11:41:29

在我的特殊情况下,我的网站无法在兼容视图中正确呈现。 我终于了解到浏览器模式会影响用户代理字符串。 我的网站样式规则基于用户代理,因此某些样式根本无法在兼容视图中应用。

我使用的是

document.documentElement.setAttribute('data-useragent', navigator.userAgent);

这样以后我可以使用 css 属性选择器,就像

html[data-useragent*='MSIE 8.0'] p {}

我通过添加解决的那样:(

html[data-useragent*='MSIE 7.0'] p {}

不关心真正的 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

document.documentElement.setAttribute('data-useragent', navigator.userAgent);

so that later I could use css attribute selectors like

html[data-useragent*='MSIE 8.0'] p {}

I solved by adding:

html[data-useragent*='MSIE 7.0'] p {}

(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).

影子是时光的心 2024-08-06 11:41:29

问题不是您使用了错误的文档类型吗?

也许:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

有关详细信息,请参阅 http://htmlhelp.com/tools/validator/doctype.html

Isn't the problem that you're using the wrong document type?

Maybe:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

For more info, see http://htmlhelp.com/tools/validator/doctype.html.

在巴黎塔顶看东京樱花 2024-08-06 11:41:29

我正在转换 XML 文档,因此无法正确设置 DOCTYPE。 我没有将其移动到 XML 无效的 之上,而是将其放在标头中。

在 PHP 中:

header("X-UA-Compatible: IE=7");

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:

header("X-UA-Compatible: IE=7");
花海 2024-08-06 11:41:29

使用 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") %>

倾城°AllureLove 2024-08-06 11:41:29

更新站点

如果您的页面包含 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文