Html 如何以编程方式禁用 IE 兼容模式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3803901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:40:34  来源:igfitidea点击:

How can I programmatically disable IE compatibility mode?

htmlxhtmlinternet-explorer-8internet-explorer-7

提问by scunliffe

I have been stuck on this one for a while - I couldn't figure out why a website renders differently in two identical versions of Internet Explorer. Half an hour ago I came across a compatibility mode button in IE which made me really angry.

我已经坚持了一段时间 - 我无法弄清楚为什么一个网站在两个相同版本的 Internet Explorer 中呈现不同。半小时前我在 IE 中遇到了一个兼容模式按钮,这让我很生气。

Disabling compatibility mode has fixed my problem.

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

Is there a way to disable it programmatically, i.e. from a web page?

有没有办法以编程方式禁用它,即从网页?

Edit:

编辑:

Just came across this blog https://blogs.msdn.com/b/askie/archive/2009/03/23/understanding-compatibility-modes-in-internet-explorer-8.aspx

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

I'll post an example code after reading the article

我会在阅读文章后发布示例代码

回答by scunliffe

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

其他选项(新老)包括:IE=5IE=7IE=8,或者IE=edge

(edge equals highest mode available)

(边缘等于可用的最高模式)

回答by Donut

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

您可能需要正确设置 DOCTYPE。查看 MSDN 关于DOCTYPE定义文档兼容性的文章以获取更多信息。

回答by Deckard

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.

另请注意,IE8 浏览器设置也可以强制执行某种模式。我有一个客户在 Intranet 模式下通过策略强制执行 IE8 兼容模式。

回答by Th? Anh Nguy?n

Please add to force IE not apply Compatibility Mode

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

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

回答by Julian Moreno

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

就我而言,我通过在标签后添加以下标签来修复它<head>

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