使用“X-UA-Compatible”为 IE8 模拟 IE7,但不为 IE9 模拟 IE7。
我有一个依赖矢量绘图的网站,对于 Internet Explorer,我使用 VML 和对于其他浏览器,我使用 SVG。 然而,IE8 不支持这两种模式,除非退回到具有 VML 的 IE7 模式。
因此,我包含 。
问题(嗯,实际上是一件好事)是 IE9 现在支持 SVG,所以我不希望它退回到性能和兼容性差得多的 IE7 模式。如何仅告诉 IE8 回退到 IE7 模式,而让 IE9 保持 IE9 模式?
现在我正在对代理进行服务器端检查是否在头部包含 EmulateIE7 字符串,但我想尽可能避免这种情况。
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.
Therefore I'm including <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
.
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?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我刚刚玩了一下,发现以下作品适合我:
那是用逗号而不是分号!
我没有看过规范,但格式类似于适用于 Chrome 框架的 content="IE=7,chrome=1"。我还发现 content="IE=7,9" 有效,但我怀疑这不是正确的格式。
编辑:
如果您的页面位于 iframe 中,请注意出现严重问题。如果您在父级处于低于 IE9 严格的任何模式的框架页面中使用上述内容,则 IE9 将回退到 IE8 模式(忽略 IE=7 请求!)。欢迎任何已知的解决方法:) 可能与 IE11 无关。
上述似乎是设计功能的副作用,iframe(我假设框架)要么全部处于 IE9 模式,要么全部低于 IE9 模式。永远不能将 IE9 框架与 << IE9 框架,请参阅 MS 问题 #599022 和 #635648。
编辑2:
请注意,IE11 仅支持“IE=edge”(不支持 IE=11),并且使用 IE=edge 对 IE 功能(包括用户代理)有重大影响。
编辑3:
IE=edge
受 IE8 到 IE11 支持。编辑 4:
X-UA-Compatible
已从 Microsoft Edge 浏览器中删除。只有 Internet Explorer 具有兼容模式。请注意,如果您在 Windows Phone 10 上的应用程序中使用 WebView,那么您仍在使用 IE11(而不是 Edge)。此外,由于多种原因,您不能相信用户代理会告诉您正确的兼容性级别,而是使用 JavaScript 中的
document.documentMode
。编辑 5:
对于某些特殊情况,例如从 ActiveX 使用 IE11 的客户(如如果您不设置此选项,包装应用程序中的 WebView 可能会将 IE11 恢复为 IE7 模式。
I just had a play and found the following works for me:
That is with a comma not a semi colon!
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.
Edit:
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.
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.
Edit 2:
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).
Edit 3:
IE=edge
is supported by IE8 through to IE11.Edit 4:
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).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.Edit 5:
IE11 still needs
X-UA-Compatible
set toIE=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.其他人提到的双模式应该工作(但不如微软所示),并且是我在MS文档中看到的最接近的东西,应该按照描述工作。下面的更新显示了元属性值应采用的正确形式。
因此,如果您使用这个:
不幸的是,由于 x-ua 兼容引擎所做的模糊版本矢量处理,您将得到的是 IE8 渲染为 IE8。请参阅此文档:
定义文档兼容性:了解内容属性值。
在该部分中,您将看到在前半部分中,他们定义了定义为大于当前浏览器版本的任何版本向量将被解释为最大的可用渲染引擎。因此,emulateIE9 被翻译为 emulateIE8。愚蠢的。
然后,实际上,他们谈论使用多个版本向量(如上面的代码片段中所示)来排除特定引擎。但由于版本逻辑模糊,这永远行不通。啊,微软。再次失败。
在元周围使用 CC 不起作用的原因是浏览器在命中 CC 时必须选择渲染引擎。根据 MS 自己的文档,x-ua 元必须位于标头中除其他元或标题之外的任何其他内容之前。
如果有人能弄清楚这一点,我会洗耳恭听,因为我迫切希望在支持 IE9 的同时排除 IE8。
重要更新:
Robocat 指出,使用逗号而不是像 Microsoft 所示的分号是执行此操作的正确方法。我测试了它,它对我有用。我更新了我的测试页。
所以正确形式是这样的(按照robocat的建议):
不正确形式是这样的(按照Microsoft的建议):
The dual mode mentioned by someone else should work (but doesn't as shown by Microsoft) and is the closest thing I've seen in MS documentation that should work as described. There's an update below that shows the proper form the meta attribute value should take.
So if you use this:
Unfortunately, what you will get is IE8 rendering as IE8 because of the fuzzy version vectoring that the x-ua-compatible engine does. See this document:
Defining Document Compatibility: Understanding Content Attribute Values on MSDN.
In that section, you'll see that in the first half, they define any version vector defined as larger than the current browser version will be interpreted as the largest available rendering engine. Therefore, emulateIE9 get's translated down to emulateIE8. Stupid.
Then, in the same breath practically, they talk about using multiple version vectors as in the code snippet above to exclude a particular engine. But because of the fuzzy version logic, that would never work. Ah, Microsoft. Fail again.
The reason why using CCs around the meta won't work, is that the browser must have chosen a rendering engine by the time it hits a CC. The x-ua meta must come before anything else in the header except other metas or the title according to MS's own documentation.
If anyone can figure this out, I'm all ears because I'm desperate to exclude IE8 from support while including IE9.
IMPORTANT UPDATE:
Robocat points out, using a comma instead of a semi-colon as Micrsoft shows is the correct way of doing this. I tested it and it worked for me. I've updated my test page.
So the correct form is this (as suggested by robocat):
The incorrect form is this (as suggested by Microsoft):
到目前为止,我已经使用了所有这些,但在 IE9 上没有任何效果:
这太令人沮丧了,这些元标记似乎都不起作用。微软,支持您认为应该在文档中起作用的内容有什么困难?我们必须花几个小时进行浏览器大战。你在浪费大家的时间。
I have so far used all these, nothing works on IE9:
this is so frustrating, none of these meta tags seems to be working. Microsoft, What is so difficult in supporting stuff you say should work in your documentation? we have to spend hours doing browser wars. You are wasting everyone's time.
如果您希望 IE 8 使用 IE7 标准,IE 9 使用 IE9 标准,这对我有用:
对于 IE9,这为我提供了 IE 9 与 IE 9 标准的兼容模式。
对于 IE8,这给了我浏览器模式 IE8 文档模式 IE7 标准
If you want IE 8 to use IE7 standards and IE 9 to use IE9 standards this one worked for me:
For IE9 this gives me IE 9 compatibility mode with IE 9 standards.
For IE8 this gives me Browser Mode IE8 Document Mode IE7 Standards
这个对我来说适用于 IE9。
This one works for IE9 to me.
我认为你需要的是:
根据
http ://blogs.msdn.com/b/ie/archive/2010/06/16/ie-s-compatibility-features-for-site-developers.aspx 因为它指出这是“...组合值的示例,以便 IE8 在 IE7 标准模式下呈现网页,而 IE9 在 IE9 标准模式下呈现网页:“
但是我无法让它工作。
I think what you need is:
according to
http://blogs.msdn.com/b/ie/archive/2010/06/16/ie-s-compatibility-features-for-site-developers.aspx as it states this as "... an example that combines values so that IE8 renders a webpage in IE7 Standards mode while IE9 renders the webpage in IE9’s Standards mode:"
However I for one can't get this to work.
哇,微软真的在这里制造了一场噩梦。我们将在未来讨论这个问题!
无论如何,这对我有用。
Wow Microsoft have really created a nightmare here. We're going to be talking about this well into the future!
Anyway this works for me.
这称为条件注释
http://en.wikipedia.org/wiki/Conditional_comment
It's called conditional comments
http://en.wikipedia.org/wiki/Conditional_comment