Html 强制 IE9 进入浏览器兼容性视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11519645/
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 01:42:09  来源:igfitidea点击:

Force IE9 into browser compatibility view

htmlinternet-explorer-9compatibilityquirks-mode

提问by F.P

I am aware of how to force IE into viewing a page in document compatibility, but what about browser compatibilityview?

我知道如何强制 IE 以文档兼容性查看页面,但是浏览器兼容性视图呢?

I have a project that only works when IE9 is in browsercompatibility view for various reasons, yet I can't find any resources on how to force IE9 to do so.

我有一个项目,由于各种原因,它只在 IE9 处于浏览器兼容性视图中时才有效,但我找不到任何关于如何强制 IE9 这样做的资源。

Everyone only talks about forcing the documentcompatibility, e.g. using

大家只讲强制文档兼容,例如使用

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

But that doesn't work in my case, because it only sets the document view. Is there a way to set the browser view, too?

但这在我的情况下不起作用,因为它只设置文档视图。有没有办法设置浏览器视图

PS: To make it abundantly clear, this is the setting I need to enforce:

PS:为了清楚起见,这是我需要强制执行的设置:

Browser Compatibility

浏览器兼容性

采纳答案by Razor

See MSDN documentation.
You should use emulateIE7 since compatibility mode is kind ofIE7:

请参阅MSDN 文档
你应该使用 emulateIE7 因为兼容模式是一种IE7:

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

Edit

编辑

If the above does not work, the other optionsare reallypoor.
Quoting from the link above:

如果以上都行不通,那其他的选择真的很差了。
引用上面的链接:

  • Microsoft has not placed the domain name of the site on a blacklist. (blacklist linked in original article is very old and not being updated, you can find a local copy on your computer)
  • An intranet admin has not placed the site on a blacklist.
  • The user has not pressed the Compatibility View button (duh)
  • The site is not in the intranet zone
  • The page is not framed by a Compatibility Mode page.
  • 微软并未将该站点的域名列入黑名单。(原文链接的黑名单很旧,没有更新,你可以在你的电脑上找到一份本地副本)
  • Intranet 管理员未将该站点列入黑名单。
  • 用户没有按下兼容性视图按钮(废话)
  • 该站点不在内网区域
  • 该页面不是由兼容模式页面构成的。

The above are, AFAIK, the only causes for compatibility mode.
Unless you are prepared to contact Microsoft directly to have your website added to the global blacklist, there isn't much you can do (unless you want to wrap your site in a frame that originates from a blacklisted domain).

以上是AFAIK,兼容模式的唯一原因。
除非您准备直接与 Microsoft 联系以将您的网站添加到全局黑名单中,否则您无能为力(除非您想将您的网站包装在源自黑名单域的框架中)。

回答by Bryce Morrison

I've tried the various methods suggested by the MSDN article at http://msdn.microsoft.com/en-us/library/jj676915(v=vs.85).aspxregarding forcing IE9 to emulate a previous version with the X-UA-Compatible header in order to display correctly.

我已经尝试了 MSDN 文章在http://msdn.microsoft.com/en-us/library/jj676915(v=vs.85).aspx关于强制 IE9 使用 X 模拟先前版本所建议的各种方法-UA-Compatible 标题以便正确显示。

In my case, the test is playing an MP4 video file in an IE9 browser which is using the default standard mode rather than the compatibility mode. Other websites have said that Internet Explorer is only configured to play MP4 files (rather than ogg and webm video files), so I assumed that would be the safest file format to test.

就我而言,测试是在使用默认标准模式而不是兼容模式的 IE9 浏览器中播放 MP4 视频文件。其他网站表示 Internet Explorer 仅配置为播放 MP4 文件(而不是 ogg 和 webm 视频文件),因此我认为这将是最安全的文件格式进行测试。

I had tested the view of the webpage using IE9 emulating the IE8 standard and the IE7 standard views of that page, and in both cases, the old standard views worked for playing the MP4 video file. And the IE9 compatibility mode also played that web page. But I forced the IE9 to revert back to the standard view in order to test a code that would work for playing the video for those who had not configured their own IE9 browser to use compatibility mode.

我已经使用 IE9 模拟该页面的 IE8 标准和 IE7 标准视图测试了网页的视图,在这两种情况下,旧的标准视图都适用于播放 MP4 视频文件。而且IE9兼容模式也能播放那个网页。但是我强迫 IE9 恢复到标准视图,以便测试一个代码,该代码可以为那些没有将自己的 IE9 浏览器配置为使用兼容模式的人播放视频。

The methods suggested by that MSDN article referenced earlier seem to be directed towards this issue, but in testing each of those methods, none of them fixed the problem of an IE9 browser playing an MP4 video file.

前面引用的 MSDN 文章建议的方法似乎是针对这个问题的,但是在测试这些方法中的每一种时,它们都没有解决 IE9 浏览器播放 MP4 视频文件的问题。

The solution to my problem came from this Stack Overflow ticket: HTML5 Video not working only in IE9

我的问题的解决方案来自这张 Stack Overflow 票证: HTML5 Video not working only in IE9

I actually had to add the following lines to the .htaccess file on the website:

我实际上不得不将以下几行添加到网站上的 .htaccess 文件中:

AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/mp4 .mov
AddType video/webm .webm

Then, I also needed to make sure that the first line of code used this:

然后,我还需要确保第一行代码使用了这个:

<!DOCTYPE html>

... rather than this:

... 而不是这个:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

I did not need to use any of the "previous version" code such as this:

我不需要使用任何“以前的版本”代码,例如:

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

On my test page, I also used the video-jscode, which I had assumed would take care of the IE9 standard problem (as it had for other web browsers). Its own code seems to have also output the following X-UA-Compatible codes:

在我的测试页面上,我还使用了video-js代码,我认为它可以解决 IE9 标准问题(就像其他 Web 浏览器一样)。它自己的代码似乎还输出了以下 X-UA-Compatible 代码:

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

However, these codes alone did not solve the problem. Ultimately, I believe it was due to the addition of the code to the .htaccess file.

但是,仅靠这些代码并不能解决问题。最终,我相信这是由于在 .htaccess 文件中添加了代码。

回答by Kesar Sisodiya

I have one solution for all (7,8,9) ie Browsers

我对所有 (7,8,9) 即浏览器都有一个解决方案

<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js" > </script>

use this java script in head tag.

在 head 标签中使用这个 java 脚本。