10

我无法禁用 IE9 中的 IE 兼容模式按钮。

我的头部和文档类型如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--[if lte IE 8]> 
  <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-en" xml:lang="en-en" class="ie8">
 <![endif]-->
<!--[if IE 9]> 
  <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-en" xml:lang="en-en" class="ie9">
<![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-en" xml:lang="en-en">
<!--<![endif]-->
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="description" content="meta content here" />
  </head>
  <body>
    <!-- page content here //-->
  </body>
</html>

如何禁用 IE9 中的兼容模式按钮?

我以为我做了我的研究。我应用了各种后备解决方案来显示从 7 到 9 及更高版本的每个 IE 中的所有内容。

客户端抱怨兼容模式在激活时会弄乱布局。有没有办法禁用该按钮?

4

5 回答 5

18
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

自 2014 年 1 月起,Google 已停止使用 Chrome 框架,因此不需要 chrome=1 部分

<meta http-equiv="X-UA-Compatible" content="IE=edge">

IE 中的“edge”强制标准模式(或最新的渲染引擎),“chrome”用于 Chrome 框架。

此处提供更多信息:

于 2012-05-17T16:03:40.203 回答
5

我在页面顶部使用条件注释来嵌入ie基于版本的类。(例如:)

<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->

结果,即使我设置了X-UA-Compatible元标记,兼容模式按钮仍然显示在 IE 中。

为了解决这个问题,我不得不将条件注释移到页面底部并使用 JS 来应用ie类。查看我的网站时,IE 中不再显示“兼容性”按钮。

<html lang="en">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=8; IE=9; IE=10; IE=EDGE; chrome=1">
  <head>
  <body>
     <!-- ..Other content... -->
  <script type="text/javascript">
   window.flagAsIE = function(version) {
     var cls = document.body.parentElement.getAttribute('class');
     document.body.parentElement.setAttribute('class', "ie ie" + version + " " + cls);
   };
  </script>

  <!--[if lt IE 7 ]><script type='text/javascript'>flagAsIE('6');</script><![endif]-->
  <!--[if IE 7 ]><script type='text/javascript'>flagAsIE('7');</script><![endif]-->
 </body>
</html>
于 2013-05-15T01:32:20.153 回答
4

这是答案:

http://blogs.msdn.com/b/jonbox/archive/2011/03/27/removing-the-ie9-compatibility-button-and-html1115-warning.aspx

更改元标记的顺序。

于 2011-07-30T08:20:29.057 回答
1

我发现导致按钮出现的是条件注释。删除这些并使用特征检测来添加我的 html 类已经解决了这个问题。再多的修补这些X-UA-Compatible东西都不会删除按钮。

我用过这组has.js检测:

if (has("css-border-radius") && !has("input-attr-placeholder")) {
    html.className += ' ie9';
}

if (!has("css-border-radius") && !has("input-attr-placeholder")) {
    html.className += ' lt-ie9';
}

if (!has("css-box-sizing")) {
    html.className += ' ie7';
}
于 2013-04-25T09:08:56.727 回答
0

问题是在您的 js 代码中的某处您正在使用浏览器嗅探代码,如 document.all、window.ActiveXObject、navigatror.userAgent、attachEvent、detachEvent 等。

使用jquery.support将所有内容替换为功能检测代码 ,按钮将消失。

于 2013-01-15T09:56:25.860 回答