如何在 WinForms 应用程序中关闭 IE WebBrowserControl 上的兼容性视图?

发布于 2024-11-24 12:37:56 字数 207 浏览 1 评论 0原文

在我的 WinForms 应用程序中,如果我使用 WebBrowser 控件,它似乎会被强制进入兼容模式。如何禁用此功能,并使其在浏览同一网站时与我的计算机上的独立 IE 的行为相同?

  • 我不想更改注册表。我希望所有内容都包含在我的应用程序中。
  • 我正在加载的网站不是我的,因此我无法对其进行更改(除非它们可以在我的应用程序中以编程方式完成)。

In my WinForms app, if I use a WebBrowser control, it seems to be forced into compatibility mode. How can I disable this, and make it behave the same as standalone IE does on my machine when browsing the same site?

  • I do not want to make registry changes. I want everything to be contained within my app.
  • The website I'm loading is not mine, so I do not have the ability to make changes to it (unless they can be done programmatically from within my app).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

栖迟 2024-12-01 12:37:56

除了配置以下注册表设置之外,没有其他方法可以执行此操作:

HKLM\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

或者如果它是 64 位 Windows 上的 32 位应用程序:

HKLM\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION`

这些设置不会显示在 WebBrowser 控件中。

欲了解更多信息,请参阅:

网络浏览器控件使用什么 IE 兼容模式?

如果链接失效:

您创建一个与可执行文件名称匹配的 DWORD 值,并将该值设置为以下之一:

7000:包含基于标准的 指令的页面在 IE7 模式下显示。
8000:包含基于标准的 指令的页面以 IE8 模式显示
8888:无论 指令如何,页面始终以 IE8 模式显示。 (这会绕过前面列出的例外情况。)
9000:使用IE9设置!
9999:强制 IE9

例如:

在此处输入图像描述

根据我自己对 IE9 的实验:

  • 9000 - 继承兼容性IE9 的全局兼容模式设置中设置的模式。 IE:
    在此处输入图像描述

  • 9999 - 强制 IE9 在主机应用程序中退出兼容模式,无论全局配置的兼容模式如何设置

您的应用程序可能需要检测哪个底层 IE 版本可用,以确定要使用哪个值:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version

或者如果它是64 位 Windows 上的 32 位应用程序:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Version

IE8 发布时还有一篇较旧的文章值得一看:

更多 IE8 可扩展性改进

您还可以在以下位置为每个用户配置这些设置:

HKCU\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

There is no way to do this other than configuring the following registry settings:

HKLM\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

or if it's a 32 bit app on 64 bit Windows:

HKLM\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION`

These settings aren't surfaced in the WebBrowser control.

For more information please see:

What IE compatibility mode does the webbrowser control use?

In case the link dies:

You create a DWORD value matching the name of your executable and set this value to one of:

7000: Pages containing standards-based <!DOCTYPE> directives are displayed in IE7 mode.
8000: Pages containing standards-based <!DOCTYPE> directives are displayed in IE8 mode
8888: Pages are always displayed in IE8 mode, regardless of the <!DOCTYPE> directive. (This bypasses the exceptions listed earlier.)
9000: Use IE9 settings!
9999: Force IE9

For example:

enter image description here

From my own experiments with IE9:

  • 9000 - inherits the compatibility mode set in IE9's global compatibility mode setting. i.e.:
    enter image description here

  • 9999 - forces IE9 out of compatibility mode in the host application regardless of the globally configured compatibility mode setting

Your application would probably need to detect which underlying IE version is available to determine which value to use:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version

or if it's a 32 bit app on 64 bit Windows:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Version

There's also this older article from when IE8 came out which is worth a look:

More IE8 Extensibility Improvements

You can also configure these settings on a per user basis under:

HKCU\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
素食主义者 2024-12-01 12:37:56

虽然这不是您所要求的,但如果您拥有该网站,您可以将以下内容添加到 html 的 head 部分:

参见:
http://msdn.microsoft.com/en-我们/library/cc288325(v=vs.85).aspx

Although it's not what you asked, if you own the site you can add the following into the head section of the html.:

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

See:
http://msdn.microsoft.com/en-us/library/cc288325(v=vs.85).aspx

红衣飘飘貌似仙 2024-12-01 12:37:56

问题的本质如下:如果用户在 IE8 中启用兼容性视图,那么它将覆盖所有页面指令。因此,如果用户在 IE 中打开了此功能,您尝试使用的任何页面或服务器变量都将无法阻止 IE 切换到兼容性视图。大多数人认为页面指令或某种秘密标头服务器变量可以修复站点。没有。如果手动覆盖该设置,这些解决方案都不起作用。我知道,这并不酷。因此,仅当用户尚未启用兼容性视图功能时,以下操作才有效。

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

要阐明在注册表中更改此设置的步骤,请编辑注册表项:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

然后添加一个名为 iexplore.exe 的新 DWORD。为此,请右键单击该键并选择“新建”>“新建”。双字。将该 DWORD 指定为十进制值 9999。这将使所有站点在没有兼容性视图的情况下呈现。要再次启用兼容性视图,请删除此 DWORD。另外,如果您希望自动执行此更改并在系统上运行批处理脚本,请查看 Michal M 的脚本。

https://gist.github.com/michal-m/1853315

Here is the skinny of the problem: If a user enables Compatibility View in IE8 then it will override all page directives. So any page or server variable you attempt to use will fail to prevent IE from switching to Compatibility View if the user has turned on this feature in IE. Most people think page directives or some kind of secret header server variable will fix the site. Nope. None of these solutions work if the setting has been manually overridden. I know, it is just not cool. So the following will work only if the user has not enabled the compatibility view feature.

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

To clarify the steps to change this in the registry edit the key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

Then add a new DWORD called iexplore.exe. To do this right-click the key and select New > DWORD. Give that DWORD the decimal value of 9999. This will make all sites render without compatibility view. To enable Compatibility View again delete this DWORD. Also if you wish to automate this change and run a batch script on your system check out Michal M's script.

https://gist.github.com/michal-m/1853315

雪化雨蝶 2024-12-01 12:37:56

我知道这是一个老问题,但有一种方法可以在 Visual Basic 2010 及更高版本中的 webbrowser 控件中插入标头,以禁用兼容性视图:

您需要做的第一件事是捕获当前网页,然后如下替换 head 标签:

Sub compatible()
' --- simple routine to disable compatible view.

    Dim the_url As String
    Dim message As String
    Dim theReplacement As String
    Dim oldMessage As String

    the_url = WebBrowser1.Url.OriginalString

    WebBrowser1.Navigate(the_url)

    message = "<head>" + Chr(13) + Chr(10) + "<meta http-equiv=" + Chr(34) + "X-UA-Compatible" + Chr(34) + "content=" + Chr(34) + "IE=edge" + Chr(34) + " />" + Chr(13) + Chr(10) + "<base href=" + Chr(34) + the_url + Chr(34) + ">"

    oldMessage = WebBrowser1.DocumentText.ToString()

    theReplacement = Replace(oldMessage, "<head>", message)
    WebBrowser1.DocumentText = theReplacement

End Sub

此代码在 webbrowser 控件中添加以下两行:

<meta http-equiv="X-UA-Compatible"content="IE=edge" />
<base href="(url of the web page)">

I know that this is an old question but there's a way to insert a header in the webbrowser control in Visual Basic 2010 and later in order to disable the compatibility view:

The first thing you need to do is to catch the current web page and then replace the head tag as follows:

Sub compatible()
' --- simple routine to disable compatible view.

    Dim the_url As String
    Dim message As String
    Dim theReplacement As String
    Dim oldMessage As String

    the_url = WebBrowser1.Url.OriginalString

    WebBrowser1.Navigate(the_url)

    message = "<head>" + Chr(13) + Chr(10) + "<meta http-equiv=" + Chr(34) + "X-UA-Compatible" + Chr(34) + "content=" + Chr(34) + "IE=edge" + Chr(34) + " />" + Chr(13) + Chr(10) + "<base href=" + Chr(34) + the_url + Chr(34) + ">"

    oldMessage = WebBrowser1.DocumentText.ToString()

    theReplacement = Replace(oldMessage, "<head>", message)
    WebBrowser1.DocumentText = theReplacement

End Sub

This code adds the two following lines in the webbrowser control:

<meta http-equiv="X-UA-Compatible"content="IE=edge" />
<base href="(url of the web page)">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文