如何在 WinForms 应用程序中关闭 IE WebBrowserControl 上的兼容性视图?
在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
除了配置以下注册表设置之外,没有其他方法可以执行此操作:
或者如果它是 64 位 Windows 上的 32 位应用程序:
这些设置不会显示在
WebBrowser
控件中。欲了解更多信息,请参阅:
如果链接失效:
您创建一个与可执行文件名称匹配的
DWORD
值,并将该值设置为以下之一:例如:
根据我自己对 IE9 的实验:
9000 - 继承兼容性IE9 的全局兼容模式设置中设置的模式。 IE:
9999 - 强制 IE9 在主机应用程序中退出兼容模式,无论全局配置的兼容模式如何设置
您的应用程序可能需要检测哪个底层 IE 版本可用,以确定要使用哪个值:
或者如果它是64 位 Windows 上的 32 位应用程序:
IE8 发布时还有一篇较旧的文章值得一看:
您还可以在以下位置为每个用户配置这些设置:
There is no way to do this other than configuring the following registry settings:
or if it's a 32 bit app on 64 bit Windows:
These settings aren't surfaced in the
WebBrowser
control.For more information please see:
In case the link dies:
You create a
DWORD
value matching the name of your executable and set this value to one of:For example:
From my own experiments with IE9:
9000 - inherits the compatibility mode set in IE9's global compatibility mode setting. i.e.:
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:
or if it's a 32 bit app on 64 bit Windows:
There's also this older article from when IE8 came out which is worth a look:
You can also configure these settings on a per user basis under:
虽然这不是您所要求的,但如果您拥有该网站,您可以将以下内容添加到 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
问题的本质如下:如果用户在 IE8 中启用兼容性视图,那么它将覆盖所有页面指令。因此,如果用户在 IE 中打开了此功能,您尝试使用的任何页面或服务器变量都将无法阻止 IE 切换到兼容性视图。大多数人认为页面指令或某种秘密标头服务器变量可以修复站点。没有。如果手动覆盖该设置,这些解决方案都不起作用。我知道,这并不酷。因此,仅当用户尚未启用兼容性视图功能时,以下操作才有效。
要阐明在注册表中更改此设置的步骤,请编辑注册表项:
然后添加一个名为 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.
To clarify the steps to change this in the registry edit the key:
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
我知道这是一个老问题,但有一种方法可以在 Visual Basic 2010 及更高版本中的 webbrowser 控件中插入标头,以禁用兼容性视图:
您需要做的第一件事是捕获当前网页,然后如下替换 head 标签:
此代码在 webbrowser 控件中添加以下两行:
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:
This code adds the two following lines in the webbrowser control: