如何禁用 IE 中的兼容性视图
我想知道如何阻止使用 IE 8 的用户进入兼容模式?
<meta http-equiv="X-UA-Compatible" content="IE=8" />
我发现了这个标签,我认为这会迫使人们保持 IE-8 模式,但我不太确定,也无法检查,因为我有 IE 9。
如果人们处于 IE 9 模式,我会强迫他们不要进入 IE 8或者 IE 7 兼容模式?
我尝试将上面的行放入我的代码中并转到 IE 9 ->工具->兼容性视图(灰显),
但“兼容性视图设置”并未灰显,似乎您可以通过那里添加网站。
那么不应该禁用吗?
I am wondering how do you stop people who are using IE 8 from going to Compatibility mode?
<meta http-equiv="X-UA-Compatible" content="IE=8" />
I found this tag and I think this forces people to stay in IE-8 mode but I am not too sure and can't check as I have IE 9.
If people are in IE 9 mode I force them to not go into IE 8 or IE 7 Compatibility mode?
I tried to put the above line in my code and went to IE 9 -> Tools -> Compatibility View(Grayed Out)
but "Compatibility View Settings" was not grayed out and it seems you could add the site through there.
So should that not disable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您所需要做的就是在 IE 中强制禁用 CM - 只需粘贴此代码(在 IE9 和 cm 下将被禁用):
来源:http://twigstechtips.blogspot.com/2010/03/css-ie8-meta-tag-to-disable.html
All you need is to force disable C.M. in IE - Just paste This code (in IE9 and under c.m. will be disabled):
Source: http://twigstechtips.blogspot.com/2010/03/css-ie8-meta-tag-to-disable.html
这应该足以迫使
IE
用户在任何IE
版本中放弃兼容模式:但是,应该注意一些警告:
下的第一个标签包含在内。只有
如果不这样做,您将在
IE9
开发工具上收到错误:X-UA-Compatible META 标记被忽略,因为文档模式已最终确定。
如果您希望此标记生效,请确保记住使用
/>
而不是仅使用>
来关闭meta
标记。从
IE11
开始,边缘模式是首选文档模式。要支持/启用该功能,请使用 HTML5 文档类型声明。
如果您需要在
IE7
上支持网络字体,请确保使用。我已经对其进行了测试,发现使用
时,在
IE7
上渲染网页字体非常不可靠。Google Chrome 浏览器内嵌框架的使用很流行,但不幸的是,它将在本月(2014 年 1 月)某个时候被放弃。
广泛的相关信息 此处。有关将其用作第一个元标记的提示位于前面提到的来源 此处,已更新。
This should be enough to force an
IE
user to drop compatibility mode in anyIE
version:However, there are a couple of caveats one should be aware of:
<head>
. Only the<title>
tag may be placed above it.If you don't do that, you'll get an error on
IE9
Dev Tools:X-UA-Compatible META tag ignored because document mode is already finalized.
If you want this markup to validate, make sure you remember to close the
meta
tag with a/>
instead of just>
.Starting with
IE11
, edge mode is the preferred document mode. To support/enable that, use the HTML5 document type declaration<!doctype html>
.If you need to support webfonts on
IE7
, make sure you use<!DOCTYPE html>
. I've tested it and found that rendering webfonts onIE7
got pretty unreliable when using<!doctype html>
.The use of Google Chrome Frame is popular, but unfortunately it's going to be dropped sometime this month, Jan. 2014.
Extensive related info here. The tip on using it as the first meta tag is on a previously mentioned source here, which has been updated.
应该强制您的页面以 IE8 标准呈现。用户可以将站点添加到兼容性列表,但此标记将优先。
一种快速检查方法是加载页面并在地址栏键入以下内容:
如果您在字符串中看到 IE7,则它正在以兼容模式加载,否则不会。
should force your page to render in IE8 standards. The user may add the site to compatibility list but this tag will take precedence.
A quick way to check would be to load the page and type the following the address bar :
If you see IE7 in the string, it is loading in compatibility mode, otherwise not.
如果您使用 ASP.NET MVC,我发现 _Layout 中的代码块中的
Response.AddHeader("X-UA-Compatible", "IE=edge,chrome=1")
可以正常工作出色地:If you're using ASP.NET MVC, I found
Response.AddHeader("X-UA-Compatible", "IE=edge,chrome=1")
in a code block in _Layout to work quite well:菲利克斯费特给出的答案对我有用。重申一下:
我将其作为代码中的第一个“元”标记。我添加了 10 和 11,因为这些是现在针对 Internet Explorer 发布的版本。
我只想评论他的答案,但我没有足够高的声誉......
The answer given by FelixFett worked for me. To reiterate:
I have it as the first 'meta' tag in my code. I added 10 and 11 as those are versions that are published now for Internet Explorer.
I would've just commented on his answer but I do not have a high enough reputation...
在 Apache 中实现此目的的另一种方法是将以下行放入网站根文件夹(或 Apache 的配置文件)的
.htaccess
中。这要求您启用
mod_headers
和mod_setenvif
模块。额外的 HTTP 标头仅发送到 IE 浏览器,而不发送到其他浏览器。
Another way to achieve this in Apache is by putting the following lines in
.htaccess
in the root folder of your website (or in Apache's config files).This requires that you have the
mod_headers
andmod_setenvif
modules enabled.The extra HTTP header only gets sent to IE browsers, and none of the others.
在 JSF 中我使用了:
In JSF I used:
向页面添加标签不会控制 Internet 控制面板(选择“工具”->“选项”时出现的对话框)中的 UI。如果您正在查看的主页可能是 google.com、msn.com、about:blank 或 example.com,则 Internet 控制面板无法知道您页面的内容,并且不会下载它在后台。
查看MSDN 上的此文档其中讨论了兼容性模式以及如何为您的站点关闭它。
Adding a tag to your page will not control the UI in the Internet Control Panel (the dialog that appears when you selection Tools -> Options). If you're looking at your homepage which could be google.com, msn.com, about:blank or example.com, the Internet Control Panel has no way of knowing what the contents of your page may be, and it will not download it in the background.
Have a look at this document on MSDN which discussed compatibility mode and how to turn it off for your site.