我可以使用 JavaScript 或 HTML 打开 IE 10 兼容性视图吗?

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

Can I turn on IE 10 Compatibility View using JavaScript or HTML?

javascripthtmlinternet-explorer-10

提问by ELAYARAJA

How can I turn on IE 10 Compatibility View programmatically in Javascript or HTML?

如何在 Javascript 或 HTML 中以编程方式打开 IE 10 兼容性视图?

I just added the following meta tag within the <head>tag, but it is not working.

我刚刚在标签中添加了以下元<head>标签,但它不起作用。

<meta http-equiv="x-ua-compatible" content="IE=EmulateIE7" >

Is there any way to do the same thing in JS?

有没有办法在 JS 中做同样的事情?

回答by Marvin

I checked the compatibility mode article on msdn - here.

我在 msdn- here上查看了兼容模式文章。

Your meta tag is still the method for enabling compatibility mode in IE 10 and IE 9.

您的元标记仍然是在 IE 10 和 IE 9 中启用兼容模式的方法。

As long as you have:

只要你有:

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
    <!-- Other meta tags etc. -->
<head>

Then it should work. You could try making the http-equiv value case sensitive (at the moment you've set it to lowercase).

那么它应该工作。您可以尝试使 http-equiv 值区分大小写(此时您已将其设置为小写)。

Also, to answer your question about JS, you can detect whether the browser is in compatibility mode by comparing the browser engine with the browser version for IE. However, this involves browser version detection, which tends to be a bit unreliable. Also, there isn't a way for you to set the user's compatibility mode in JS. So, for the moment at least, you'll have to stick with the meta tags.

另外,为了回答您关于JS的问题,您可以通过比较浏览器引擎和IE浏览器版本来检测浏览器是否处于兼容模式。但是,这涉及浏览器版本检测,这往往有点不可靠。此外,您无法在 JS 中设置用户的兼容模式。因此,至少就目前而言,您必须坚持使用元标记。

I hope this helps.

我希望这有帮助。



A good plugin to allow you to view http header information is IEhttpheaders. Just download it from that link & install. Then, when you start IE, go to the tools menu and select 'DisplayIEhttpHeaders...'. When you visit your site it will list the header response. If you modify your answer to include the response, then we can see if it's the problem.

IEhttpheaders是一个允许您查看 http 标头信息的好插件。只需从该链接下载并安装即可。然后,当您启动 IE 时,转到工具菜单并选择“DisplayIEhttpHeaders...”。当您访问您的网站时,它会列出标头响应。如果您修改答案以包含响应,那么我们可以查看是否是问题所在。

回答by Paul D. Waite

You say “I just added the following meta tag within the header tag”. Do you mean:

你说“我刚刚在标题标签中添加了以下元标签”。你的意思是:

  1. The <header>tag
  2. The <head>tag?
  1. <header>标签
  2. <head>标签?

The x-ua-compatiblemeta tag does need to go inside the <head>tag, not a <header>tag.

x-ua-compatiblemeta标签并不需要去里面<head>的标签,而不是<header>标签。