javascript 页面以 IE7 文档模式打开,而不是 IE9

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

page opens in IE7 document mode instead of IE9

javascriptinternet-explorer-9meta-tagsie8-browser-modeie-developer-tools

提问by JasonBK

I know many variations of this question have been asked here but so far no solutions I have tried work for me.

我知道这里已经问过这个问题的许多变体,但到目前为止,我没有尝试过对我有用的解决方案。

I would like my web app to open in IE9 document mode in IE. When I open the page now, it always opens in 'Internet Explorer7 Standards), while 'Internet Explorer9 standards' is listed as the page default. I have tried several variations of tagss, including

我希望我的网络应用程序在 IE 中以 IE9 文档模式打开。当我现在打开页面时,它总是在“Internet Explorer7 标准”中打开,而“Internet Explorer9 标准”被列为默认页面。我尝试了几种标签变体,包括

<meta http-equiv="X-UA-Compatible" value="IE=Edge">

and

<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">

(both right after the head tag)

(都在 head 标签之后)

I have also tried conditional statements, such as this example from S.O.:

我也尝试过条件语句,例如来自 SO 的这个例子:

<!--[if IE 7 ]> <body class="ie7> <![endif]-->
<!--[if IE 8 ]> <body class="ie8> <![endif]-->
<!--[if gt IE 8]><!--><body><!--<![endif]-->

Currently I am using: <!DOCTYPE html>

目前我正在使用: <!DOCTYPE html>

Of course I can manually switch the mode in F12, but I would like to site to open directly in IE9 Document mode (the Compatibility mode always defaults to IE9 Compatibility mode).

当然我可以在F12手动切换模式,但是我想站点直接在IE9文档模式下打开(兼容模式总是默认为IE9兼容模式)。

Currently I am working on an intranet development server; I have read that this may be a factor? But I would really prefer any solutions to be client-side, that I can add to the JS/HTML.....

目前我正在做一个内网开发服务器;我读过这可能是一个因素?但我真的更喜欢客户端的任何解决方案,我可以添加到 JS/HTML .....

回答by Sampson

Developer Tools Manually Overriding the Document Mode

开发者工具手动覆盖文档模式

If Internet Explorer 9 Standards is listed as the Page Default, this means you may have manually changed it to Internet Explorer 7 Standards via the tools. Just switch it back to Internet Explorer 9 Standards in the F12 Developer Tools themselves.

如果 Internet Explorer 9 标准被列为页面默认值,这意味着您可能已通过工具手动将其更改为 Internet Explorer 7 标准。只需在 F12 开发人员工具中将其切换回 Internet Explorer 9 标准即可。

The tools will remember your explicit request to show the page in another Document Mode, and as such not revert to the page default. Consider the following from MSDN:

这些工具会记住您在另一种文档模式下显示页面的明确请求,因此不会恢复到页面默认值。考虑来自 MSDN 的以下内容:

When you first load a webpage, F12 tools determines the default Document Modeand selects the appropriate mode. The text Page defaultin parentheses indicates the default mode of the webpage. A check mark appears next to the current mode of the document. Changing the mode causes the webpage to refresh, and remains in this mode until another mode is chosen or the browser is closed.

Navigating the F12 Developer Tools Interface(emphasis in original)

首次加载网页时,F12 工具会确定默认文档模式并选择适当的模式。括号中的文本Page default表示网页的默认模式。文档的当前模式旁边会出现一个复选标记。更改模式会导致网页刷新,并保持此模式直到选择其他模式或关闭浏览器。

导航 F12 开发人员工具界面(强调原文)

If you'd like confirm this answer, open up a new browser window and navigate to http://stackoverflow.com. You should note in the F12 Developer Tools that it loads with a Document Mode of "Standards" (IE9 Standards if you're in IE9).

如果你想确认这个答案,打开一个新的浏览器窗口并导航到http://stackoverflow.com。您应该在 F12 开发人员工具中注意到它以“标准”的文档模式加载(如果您使用的是 IE9,则为 IE9 标准)。

Switch Stack Overflow's Document Mode to IE7 Standards and refresh the browser. After refreshing you'll find that the browser stays with Document Mode: Internet Explorer 7 Standards, and lists Internet Explorer 9 Standards as (Page Default).

将 Stack Overflow 的文档模式切换为 IE7 标准并刷新浏览器。刷新后,您会发现浏览器保持文档模式:Internet Explorer 7 标准,并将 Internet Explorer 9 标准列为(页面默认)。

enter image description here

在此处输入图片说明

Compatibility View Settings

兼容性视图设置

According to the MSDN resource How Internet Explorer Chooses Between Document Modes, the only other potential cause for this would be Compatibility View Settings.

根据 MSDN 资源How Internet Explorer 在文档模式之间选择,唯一的其他潜在原因是兼容性视图设置。

In Internet Explorer 9, click Tools, then Compatibility View Settings. You can find your settings for Intranet sites there. In Internet Explorer 10 (Desktop Mode), you may have to press Altto reveal the Tools menu item.

在 Internet Explorer 9 中,单击工具,然后单击兼容性视图设置。您可以在那里找到 Intranet 站点的设置。在 Internet Explorer 10(桌面模式)中,您可能需要按Alt才能显示工具菜单项。

enter image description here

在此处输入图片说明

回答by Samir Galchar

Just put following code and your IE browser would open by default in defined compatible view.

只需输入以下代码,您的 IE 浏览器就会默认在定义的兼容视图中打开。

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

You can change "IE=EmulateIE9" to "IE=EmulateIE8" if you want make IE8 as default compatibility view.

如果您想让 IE8 作为默认兼容性视图,您可以将“IE=EmulateIE9”更改为“IE=EmulateIE8”。

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

回答by sfarbota

The issue in my case was that a group policy had been applied on my company-issued laptop which explicitly set the domain that I was using to render in Compatibility Mode. I found this by checking the IE console (F12):

就我而言,问题是我公司发行的笔记本电脑上应用了组策略,该策略明确设置了我用于在兼容模式下呈现的域。我通过检查 IE 控制台 ( F12)发现了这一点:

enter image description here

在此处输入图片说明

And I verified this by running the following command on my machine, which generated a report of applied group policies on my machine:

我通过在我的机器上运行以下命令来验证这一点,该命令在我的机器上生成了应用组策略的报告:

gpresult /h C:\gpresult.html

The report had a section like this, which included the root domain of the website I was working on:

该报告有一个这样的部分,其中包括我正在处理的网站的根域:

enter image description here

在此处输入图片说明

回答by Vish

You can put the following code sample too.

您也可以放置以下代码示例。

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

This will load your application in the default browser mode. And specially make sure to include this meta tag as the first tag just after the head tag. Other wise it will not work.

这将以默认浏览器模式加载您的应用程序。并特别确保将此元标记包含在 head 标记之后的第一个标记中。否则它不会工作。