C# 如何以编程方式关闭 IE8 WebBrowser 控件中的怪癖模式?

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

How to programmatically turn off quirks mode in IE8 WebBrowser control?

c#internet-explorer-8webbrowser-controlstandards-compliancequirks-mode

提问by Tony the Pony

I want to use IE8 as a WebBrowser control in a C# application. How can I disable "quirks mode" and force IE into standards compliance (as far as it is implemented)?

我想在 C# 应用程序中使用 IE8 作为 WebBrowser 控件。如何禁用“怪癖模式”并强制 IE 符合标准(就其实施而言)?

采纳答案by Daniel LeCheminant

I think the issue you're facing is described in IEBlog: WebBrowser Control Rendering Modes in IE8:

我认为您面临的问题在IEBlog: WebBrowser Control Rendering Modes in IE8 中有所描述:

While webmasters can easily alter their site to render properly in the new version of IE, many software vendors do not have the resources to instantly push out new versions of their applications with updated internal pages. In order to ensure that these existing applications remain in working order, IE8 renders pages running within instances of the WebBrowser control in IE7 Standards Mode by default.

虽然网站管理员可以轻松地更改他们的站点以在新版本的 IE 中正确呈现,但许多软件供应商没有资源立即推出具有更新内部页面的新版本应用程序。为了确保这些现有应用程序保持正常工作, IE8 默认呈现在 IE7 标准模式下的 WebBrowser 控件实例中运行的页面。

Here I should note that the comments on the page say the above is incorrect, and that "IE8 renders pages running within instances of the WebBrowser control in IE7 Strict Mode OR Quirks mode by default, depending on the page's doctype."

在这里我应该注意,页面上的评论说上述内容是不正确的,并且“ IE8 默认呈现在 IE7 严格模式或 Quirks 模式下的 WebBrowser 控件实例中运行的页面,具体取决于页面的文档类型。”

The solution is as follows:

解决方法如下:

When an executable loads an instance of the WebBrowser control it scans the registry to check whether the executable wants IE7 Standards or IE8 Standards mode.

...

To run in IE8 Standards Mode insert the following registry value:

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_NATIVE_DOCUMENT_MODE]

"MyApplication.exe"=dword:13880

In both of these instances, MyApplication.exe should be replaced with the name of the executable that will be running WebBrowser controls in a specified mode.

当可执行文件加载 WebBrowser 控件的实例时,它会扫描注册表以检查该可执行文件是否需要 IE7 标准或 IE8 标准模式。

...

要在 IE8 标准模式下运行,请插入以下注册表值:

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_NATIVE_DOCUMENT_MODE]

"MyApplication.exe"=dword:13880

在这两种情况下,应将 MyApplication.exe 替换为将以指定模式运行 WebBrowser 控件的可执行文件的名称。

So it sounds like the "programmatic" solution is to write a key in the registry saying you want IE8 Standards mode for WebBrowsercontrols in your specific application.

因此,听起来“程序化”解决方案是在注册表中写入一个键,说明您希望WebBrowser特定应用程序中的控件采用IE8 标准模式。

回答by Jon Skeet

The last I heard was that IE8 would use standards mode by default. Are you seeing an actual problem with the latest beta version? Are you sure it's rendering in quirks mode to start with, without a user explicitly hitting the compatibility view button?

我最后听说 IE8 会默认使用标准模式。您是否发现最新测试版存在实际问题?您确定它在开始时以 quirks 模式呈现,而没有用户明确点击兼容性视图按钮吗?

回答by Sire

Please note there have been some changes since the beta, the registry keys have been renamed etc. Read more here.

请注意,自测试版以来发生了一些变化,注册表项已重命名等 。在此处阅读更多内容

回答by Elijah

If you don't want to use the registry key technique, you could insert the following tag:

如果您不想使用注册表项技术,您可以插入以下标签:

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

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

The "content" attribute forces rendering in various modes.

“内容”属性强制以各种模式呈现。

回答by Dirk Bester

This has actual code to programmatically do this and handles up to IE11 so far:

这具有以编程方式执行此操作的实际代码,并且到目前为止最多可处理 IE11:

C# webbrowser Ajax call

C# webbrowser Ajax 调用