Browserswitch然后使用meta http-equiv ="X-UA-Compatible" - Documentmodus已经完成

Joe*_*erg 1 internet-explorer browser-detection internet-explorer-9 x-ua-compatible

我们对某些Internet Explorer版本有一些奇怪的问题,所以我们有一个浏览器开关

<head>
<!--[if IE 6]>
  <!-- load some IE6 stuff -->
  <meta http-equiv="X-UA-Compatible" content="IE=6" />
<![endif]-->
<!--[if IE 7]>
  <!-- load some IE7 stuff -->
  <meta http-equiv="X-UA-Compatible" content="IE=6" />
<![endif]-->

<!--[if IE 8]>
  <!-- load some IE8 stuff -->
  <meta http-equiv="X-UA-Compatible" content="IE=8" />
<![endif]-->

<!--[if IE 9]>
  <!-- load some IE9 stuff -->
  <meta http-equiv="X-UA-Compatible" content="IE=8" />
<![endif]-->
</head>
Run Code Online (Sandbox Code Playgroud)

如果我像这样加载它,我在IE9 Developer附加组件中看到:

HTML1115:与X-UA兼容的META-Tag("IE = 8")被忽略,因为documentmodus已经加载.

(最初是德语,所以我应该翻译)

并且文档模式仍然是IE9

如果我在我的<head>标签中写得很难:

   <meta http-equiv="X-UA-Compatible" content="IE=8" />
Run Code Online (Sandbox Code Playgroud)

IE9将作为IE8加载,所以这可行,但那时IE6的东西当然是错误的....

那么有没有办法像我第一次尝试那样做?

dur*_*uri 5

你不能这样做.在X-UA-Compatible meta元素之前可以使用的东西数量有限.

X-UA-Compatible标头不区分大小写; 但是,它必须出现在除了title元素和其他元元素之外的所有其他元素之前的网页标题(HEAD部分)中.

(来自http://msdn.microsoft.com/en-us/library/ie/cc288325%28v=vs.85%29.aspx)

这就是您的标记无法按预期工作的原因 - 条件注释会导致X-UA-Compatible忽略所有后续声明.

另请注意,X-UA-Compatible仅在IE8和更新版本中支持 - 在IE6和IE7中完全忽略它.如果您仅使用以下内容:

<meta http-equiv="X-UA-Compatible" content="IE=8" />
Run Code Online (Sandbox Code Playgroud)

然后IE6和IE7将使用他们自己的渲染,IE8以上的所有版本将文档呈现为IE8.