强制Internet Explorer 9使用IE 9模式

Joh*_*ika 18 doctype internet-explorer cross-browser internet-explorer-9

我在顶部附近使用带有X-UA兼容元标记的HTML5 doctype:

<!DOCTYPE html>
<!--[if lt IE 7]> <html lang="en-us" class="ie6"> <![endif]-->
<!--[if IE 7]>    <html lang="en-us" class="ie7"> <![endif]-->
<!--[if IE 8]>    <html lang="en-us" class="ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en-us"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    ...
Run Code Online (Sandbox Code Playgroud)

但是某些用户的Internet Explorer 9正在兼容性视图中呈现页面.我怀疑这是因为他们打开了"在兼容性视图中显示所有网站"设置.有没有办法强制IE9使用IE9浏览器和文档模式?

Joh*_*ika 26

事实证明,解决方案是在HTTP标头中而不是在HTML中设置X-UA-Compatible:

 X-UA-Compatible: IE=edge,chrome=1
Run Code Online (Sandbox Code Playgroud)

这将强制Internet Explorer使用最新的呈现引擎,即使"在兼容性视图中显示所有网站"已打开.


小智 10

它也在<head>html中使用它:

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


小智 5

X-UA-COMPATIBLE元标记必须是头部内的第一个标记,否则它将无法工作.请参阅此答案:https: //stackoverflow.com/a/22233206/3329906.

所有这些http头文件都是矫枉过正的.