如何禁用 IE 中的兼容性视图

发布于 2024-11-15 13:42:41 字数 381 浏览 0 评论 0原文

我想知道如何阻止使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

娇柔作态 2024-11-22 13:42:41

您所需要做的就是在 IE 中强制禁用 CM - 只需粘贴此代码(在 IE9 和 cm 下将被禁用):

<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" />

来源: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):

<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" />

Source: http://twigstechtips.blogspot.com/2010/03/css-ie8-meta-tag-to-disable.html

橘和柠 2024-11-22 13:42:41

这应该足以迫使 IE 用户在任何 IE 版本中放弃兼容模式:

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

但是,应该注意一些警告:

  • 上面的元标记应作为 下的第一个标签包含在内。只有 </code> 标签可以放置在其上方。

如果不这样做,您将在 IE9 开发工具上收到错误:X-UA-Compatible META 标记被忽略,因为文档模式已最终确定。

  • 如果您希望此标记生效,请确保记住使用 /> 而不是仅使用 > 来关闭 meta 标记。

  • IE11开始,边缘模式是首选文档模式。要支持/启用该功能,请使用 HTML5 文档类型声明

  • 如果您需要在 IE7 上支持网络字体,请确保使用 。我已经对其进行了测试,发现使用 时,在 IE7 上渲染网页字体非常不可靠。

Google Chrome 浏览器内嵌框架的使用很流行,但不幸的是,它将在本月(2014 年 1 月)某个时候被放弃。

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

广泛的相关信息 此处。有关将其用作第一个元标记的提示位于前面提到的来源 此处,已更新。

This should be enough to force an IE user to drop compatibility mode in any IE version:

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

However, there are a couple of caveats one should be aware of:

  • The meta tag above should be included as the very first tag under <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 on IE7 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.

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

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.

镜花水月 2024-11-22 13:42:41
<meta http-equiv="X-UA-Compatible" content="IE=8" /> 

应该强制您的页面以 IE8 标准呈现。用户可以将站点添加到兼容性列表,但此标记将优先。

一种快速检查方法是加载页面并在地址栏键入以下内容:

javascript:alert(navigator.userAgent) 

如果您在字符串中看到 IE7,则它正在以兼容模式加载,否则不会。

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

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 :

javascript:alert(navigator.userAgent) 

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") 可以正常工作出色地:

@Code
    Response.AddHeader("X-UA-Compatible", "IE=edge,chrome=1")
End Code
<!DOCTYPE html>
everything else

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:

@Code
    Response.AddHeader("X-UA-Compatible", "IE=edge,chrome=1")
End Code
<!DOCTYPE html>
everything else
格子衫的從容 2024-11-22 13:42:41

菲利克斯费特给出的答案对我有用。重申一下:

<meta http-equiv="X-UA-Compatible" content="IE=11; IE=10; IE=9; IE=8; IE=7; IE=EDGE" />

我将其作为代码中的第一个“元”标记。我添加了 10 和 11,因为这些是现在针对 Internet Explorer 发布的版本。

我只想评论他的答案,但我没有足够高的声誉......

The answer given by FelixFett worked for me. To reiterate:

<meta http-equiv="X-UA-Compatible" content="IE=11; IE=10; IE=9; IE=8; IE=7; IE=EDGE" />

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...

甜味超标? 2024-11-22 13:42:41

在 Apache 中实现此目的的另一种方法是将以下行放入网站根文件夹(或 Apache 的配置文件)的 .htaccess 中。

BrowserMatch "MSIE" isIE
BrowserMatch "Trident" isIE
Header set X-UA-Compatible "IE=edge" env=isIE

这要求您启用 mod_headersmod_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).

BrowserMatch "MSIE" isIE
BrowserMatch "Trident" isIE
Header set X-UA-Compatible "IE=edge" env=isIE

This requires that you have the mod_headers and mod_setenvif modules enabled.

The extra HTTP header only gets sent to IE browsers, and none of the others.

你是年少的欢喜 2024-11-22 13:42:41

在 JSF 中我使用了:

<h:head>
    <f:facet name="first">
        <meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
    </f:facet>

    <!-- ... other meta tags ... -->

</h:head>

In JSF I used:

<h:head>
    <f:facet name="first">
        <meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
    </f:facet>

    <!-- ... other meta tags ... -->

</h:head>
[旋木] 2024-11-22 13:42:41

向页面添加标签不会控制 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文