使用“X-UA-Compatible"为 IE8 模拟 IE7,但不能为 IE9 模拟 [英] Emulate IE7 for IE8 but not for IE9 using "X-UA-Compatible"

查看:22
本文介绍了使用“X-UA-Compatible"为 IE8 模拟 IE7,但不能为 IE9 模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个依赖矢量绘图的网站,对于 Internet Explorer,我使用的是 VML 对于其他浏览器,我正在使用 SVG.然而,IE8 不支持两者,除非退回到具有 VML 的 IE7 模式.

I have a website depending on vector drawing, for Internet Explorer I'm using VML and for other browsers I'm using SVG. IE8 however, doesn't have support for neither without falling back to IE7-mode which has VML.

因此我包含了 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>.

问题(嗯,实际上是一件好事)是 IE9 现在支持 SVG,所以我不希望它回退到性能和兼容性更差的 IE7 模式.如何只让 IE8 回退到 IE7 模式,而让 IE9 保持在 IE9 模式?

The problem (well, actually a good thing) is that IE9 now has support for SVG so I don't want it to fall back to IE7-mode which has much worse performance and compatibility. How do I tell only IE8 to fall back to IE7-mode but let IE9 stay in IE9-mode?

现在我正在对代理进行服务器端检查是否在头部包含 EmulateIE7 字符串,但我想尽可能避免这种情况.

Right now I'm doing a server side check on the agent whether to include the EmulateIE7-string in the head or not but I want to avoid this as far as it's possible.

推荐答案

我刚玩了一场,发现以下作品适合我:

I just had a play and found the following works for me:

<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" >

那是逗号而不是分号!

我没有看过规范,但格式类似于适用于 Chrome Frame 的 content="IE=7,chrome=1".我还发现 content="IE=7,9" 有效,但我怀疑这不是正确的格式.

I haven't looked at the spec, but the format is similar to content="IE=7,chrome=1" that works for Chrome Frame. I also found that content="IE=7,9" works but I suspect that is not a correct format.

如果您的页面在 iframe 中,请注意一个严重的问题.如果您在父页面处于any 模式下小于 IE9 严格的框架页面中使用上述内容,则 IE9 将回退到 IE8 模式(忽略 IE=7 请求!).欢迎任何已知的解决方法:) 可能与 IE11 无关.

Beware of a serious problem if your page is in a iframe. If you use the above in a framed page where the parent is in any mode less than IE9 strict, then IE9 will fall back to IE8 mode (ignoring the IE=7 request!). Any known workarounds welcome :) Might not be relevant to IE11.

以上似乎是设计功能的副作用,即 iframe(我假设框架)要么全部处于 IE9 模式,要么全部低于 IE9 模式.永远不能将 IE9 框架与 < 混合使用.IE9 框架,请参阅 MS 问题 #599022#635648.

The above seems to be a side effect of the by design feature, that iframes (and I presume frames) are either all in IE9 mode, or all are less than IE9 mode. One can never mix IE9 frames with < IE9 frames, see MS issues #599022 and #635648.

编辑 2:

请注意,IE11 仅支持IE=edge"(不支持 IE=11),并且使用 IE=edge 会对 IE 功能(包括用户代理)产生重大影响.

Beware that IE11 only supports "IE=edge" (not IE=11), and that using IE=edge has significant effects upon IE functionality (including the user agent).

编辑 3:

  • Fantastic flow chart explaining how IE works out what mode to use for IE9
  • IE=edge is supported by IE8 through to IE11.
  • The Meta tag takes precedence over the HTTP header (which can be used instead of the meta tag)
  • Some more X-UA-Compatible info for IE10.

编辑 4:

X-UA-Compatible 已从 Microsoft Edge 浏览器中移除.只有 Internet Explorer 具有兼容模式.请注意,如果您在 Windows Phone 10 上的应用程序中使用 WebView,那么您仍在使用 IE11(而不是 Edge).

X-UA-Compatible was removed from the Microsoft Edge browser. Only Internet Explorer has the compatibility modes. Beware that if you are using the WebView within an App on Windows Phone 10, then you are still using IE11 (not Edge).

同样出于各种原因,您不能相信用户代理会告诉您正确的兼容性级别,而是使用 JavaScript 中的 document.documentMode.

Also for a variety of reasons you cannot trust the user agent to tell you the correct compatibility level, instead use document.documentMode from JavaScript.

编辑 5:

IE11 仍然需要将 X-UA-Compatible 设置为 IE=EDGE 以用于某些极端情况,例如如果您不设置此项,使用 ActiveX 中的 IE11(作为包装应用程序中的 WebView)的客户可以将 IE11 降回 IE7 模式.

IE11 still needs X-UA-Compatible set to IE=EDGE for some corner cases e.g. a customer using IE11 from ActiveX (as WebView within a wrapper application) can drop IE11 back to IE7 mode if you don't set this.

这篇关于使用“X-UA-Compatible"为 IE8 模拟 IE7,但不能为 IE9 模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆