如何通过编程禁用 IE 兼容模式?

这个问题困扰了我一段时间——我不明白为什么一个网站在两个相同版本的 Internet Explorer 中呈现的效果会有所不同。半小时前,我偶然发现了 IE 中的一个兼容模式按钮,这让我非常生气。

禁用兼容模式解决了我的问题。

有没有办法通过编程方式禁用它,比如从网页上?

编辑:

刚看到这个博客 https://blogs.msdn.com/b/askie/archive/2009/03/23/understanding-compatibility-modes-in-internet-explorer-8.aspx

在阅读本文之后,我将发布一个示例代码

76054 次浏览

You probably need to set your DOCTYPE correctly. Check out MSDN's articles on DOCTYPE and Defining Document Compatibility for more info.

If you want the "old" rendering, and no button to show up on the toolbar so that users can switch modes you can use this:

<head>
<!-- Mimic Internet Explorer 7 -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" >
<title>My Web Page</title>
</head>

other options (old and new) include:IE=5, IE=7, IE=8, or IE=edge

(edge equals highest mode available)

Please also note that also IE8 browser settings can enforce a certain mode. I have a customer who has IE8 compatibility mode enforced by policy in intranet mode.

请添加以强制IE不应用兼容模式

<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">

In my case, I fixed it by adding the following tag after the <head> tag:

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