IE9 WebBrowser 控件是否支持 IE9 的所有功能,包括 SVG?
我最近升级到了 IE9-beta。现在,在我的 .Net (3.5) WinForm 应用程序中,我想使用 WebBrowser
控件。
那么我的问题是,WebBrowser
控件是否会展现IE9的所有属性和功能?
我担心的是,我想在上面渲染一些 SVG 图形。
I recently upgraded to IE9-beta. Now, In my .Net (3.5) WinForm application I want to use WebBrowser
control.
So my question is, whether the WebBrowser
control will exhibit all properties and functions of IE9?
My concern is, I want to render some SVG graphics on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
WebBrowser 控件将使用您安装的任何版本的 IE,但出于兼容性原因,默认情况下它将以 IE7 标准模式呈现页面。
如果您想利用 IE9 的新功能,则应在 < 内添加元标记
HTML 页面的 code> 标记。
必须在</code> 标签可以出现在它之前)。
中的 CSS、JavaScript 文件等的任何链接之前添加此元标记才能正常工作(仅限其他
标记)或者
另一种方法是将注册表项添加到:
并在其中添加值为“9000”的“myApplicationName.exe”,以强制 WebBrowser 控件以 IE9 模式显示页面。尽管还有您也可以使用其他值 另外,请注意,这些文档并不完全准确,因为无论您使用什么值,似乎都不可能让页面在 IE 8 模式下呈现。
将注册表项添加到 HKCU 而不是 HKLM 中的同一路径也可以 - 这很有用,因为写入 HKLM 需要管理员权限,而 HKCU 则不需要。
WebBrowser control will use whatever version of IE you have installed, but for compatibility reasons it will render pages in IE7 Standards mode by default.
If you want to take advantage of new IE9 features, you should add the meta tag
<meta http-equiv="X-UA-Compatible" content="IE=9" >
inside the<head>
tag of your HTML page.This meta tag must be added before any links to CSS, JavaScript files etc that are also in your
<head>
to work properly though (only other<meta>
tags or the<title>
tag can come before it).An alternative is to add a registry entry to:
And in there add 'myApplicationName.exe' with value '9000' to force the WebBrowser control to display pages in IE9 mode. Though there are other values you can use too too, note that these docs aren't entirely accurate as it does not seem possible to get a page to render in IE 8 mode whatever value you use.
Adding the registry key to the same path in HKCU instead of HKLM will also work - this is useful as writing to HKLM requires admin privileges where as HKCU does not.
IE9“版本”的WebBrowser控件与IE8版本一样,实际上是多个浏览器合二为一。与 IE8 版本不同,您可以通过更改文档类型对页面内的渲染模式进行更多控制。当然,要更改浏览器模式,您必须像之前的答案一样设置注册表。以下是 FEATURE_BROWSER_EMULATION 的 reg 文件片段:
这是完整的代码集:
网页在IE9中显示
标准模式,无论
!DOCTYPE 指令。
指令在 IE9 模式下显示。
在 IE8 标准模式下显示,
无论 !DOCTYPE 指令如何。
基于标准的 !DOCTYPE 指令
在IE8模式下显示。
基于标准的 !DOCTYPE 指令
以 IE7 标准模式显示。
完整文档:
http://msdn.microsoft .com/en-us/library/ee330730%28VS.85%29.aspx#browser_emulation
The IE9 "version" of the WebBrowser control, like the IE8 version, is actually several browsers in one. Unlike the IE8 version, you do have a little more control over the rendering mode inside the page by changing the doctype. Of course, to change the browser mode you have to set your registry like the earlier answer. Here is a reg file fragment for FEATURE_BROWSER_EMULATION:
Here is the complete set of codes:
Webpages are displayed in IE9
Standards mode, regardless of the
!DOCTYPE directive.
directives are displayed in IE9 mode.
displayed in IE8 Standards mode,
regardless of the !DOCTYPE directive.
standards-based !DOCTYPE directives
are displayed in IE8 mode.
standards-based !DOCTYPE directives
are displayed in IE7 Standards mode.
The full docs:
http://msdn.microsoft.com/en-us/library/ee330730%28VS.85%29.aspx#browser_emulation
谢天谢地我发现了这个。下面的内容非常重要:
如果没有这个,我生成的所有报告都无法在 IE9 安装后工作,尽管在 IE8 中工作得很好。它们会在 Web 浏览器控件中正确显示,但当我调用 .Print() 时,会出现字母丢失、空白过多等情况。它们只是基本的 HTML,即使在 Mosaic 中也应该能够呈现。呵呵,不知道为什么 IE7 兼容模式会变得混乱。值得注意的是,您可以 .Print() 同一页 5 次,并且每次都会丢失不同的字母。它甚至会延续到 PDF 输出中,所以它肯定是浏览器。
Thank goodness I found this. The following is extremely important:
Without this, none of the reports I'd been generating would work post IE9 install despite having worked great in IE8. They would show up properly in a web browser control, but there would be missing letters, jacked up white space, etc, when I called .Print(). They were just basic HTML that should be capable of being rendered even in Mosaic. heh Not sure why the IE7 compatibility mode was going haywire. Notably, you could .Print() the same page 5 times and have it be missing different letters each time. It would even carry over into PDF output, so it's definitely the browser.
关于 64 位 Windows 的注释似乎让一些人感到困惑。
如果您的应用程序在 64 位 Windows 下运行,您可能必须在 [HKLM\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION] 下设置 DWORD。
A note about 64bit Windows which seems to trip up a few folks.
If your app is running under 64bit Windows, you likely have to set the DWORD under [HKLM\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION] instead.
为了完整起见...
对于 32 位操作系统,您必须将注册表项添加到:
********或********
对于 64 位操作系统,您必须将注册表项添加到:
此条目必须是一个
DWORD
,其名称是托管 Webbrowser 控件的可执行文件的名称;即:myappname.exe(不要像 MSDN 网页中那样使用“Contoso.exe”...它只是一个占位符名称)
然后根据以下表格为其指定一个
DWORD
值:http://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx#browser_emulation
我更改为十进制 11001 或十六进制 0x2AF9 --- (IE 11 EMULATION ),因为这不是默认值(如果您安装了 IE 11 - 或任何版本)。
该 MSDN 文章包含有关影响 Internet Explorer Web 浏览器行为的其他几项注册表更改的注释。
Just to be complete...
For 32 bit OS you must add a registry entry to:
*******OR*******
For 64 bit OS you must add a registry entry to:
This entry must be a
DWORD
, with the name being the name of your executable, that hosts the Webbrowser control; i.e.:myappname.exe (DON'T USE "Contoso.exe" as in the MSDN web page...it's just a placeholder name)
Then give it a
DWORD
value, according to the table on:http://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx#browser_emulation
I changed to 11001 decimal or 0x2AF9 hex --- (IE 11 EMULATION) since that isn't the DEFAULT value (if you have IE 11 installed -- or whatever version).
That MSDN article contains notes on several other Registry changes that affects Internet Explorer web browser behavior.
我知道这个帖子很旧,并且已经有全面的答案。
以防万一您不知道这一点:
您不必硬编码 IE 版本号为
I know this thread is old and there are already comprehensive answers.
Just in case you don't know this:
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
You don't have to hardcode IE version number as
<meta http-equiv="X-UA-Compatible" content="IE=9" >
我完全同意所提供的解决方案,但我认为一些澄清很重要,我认为可能是必要的。
对于每个需要添加具有所提供值的 DWORD 的进程(另请参阅:vshost.exe、yourWinformApplication.exe.svchost 或 application.exe 的名称),在我的例子中,我在 application 中保留 9000(十进制)名称和运行平稳且无错误的脚本。
最常见的错误是认为有必要按原样添加“contoso.exe”并认为这一切都有效!
I totally agree with the solution provided, but I think a little clarification is important I think, might be necessary.
For each process (read also: vshost.exe, yourWinformApplication.exe.svchost, or the name of your application.exe) that will need to add a DWORD with the value provided, in my case I leave 9000 (in decimal) in application name and running smoothly and error-free script.
the most common mistake is to believe that it is necessary to add "contoso.exe" AS IS and think it all work!
是的,WebBrowser 控件使用您安装的任何版本的 IE。当然,这意味着如果您在装有 IE 8 的计算机上运行应用程序,那么您所依赖的 IE 9 功能将不可用。
Yes, WebBrowser control uses whatever version of IE you have installed. This means of course that if you run your application on a machine with IE 8 then the IE 9 features you depend on will not be available.
我找到了这个解决方案,但它对我不起作用!因为我使用的是 64 位,所以我必须更换注册表:
而不是每个人都在谈论的注册表:
I came to this solution and it did not worked for me! Because I was using 64bit I had to replace the registry:
Instead of the one that everyone talks about:
我喜欢下面的 (C#) 代码,它为您的应用程序设置注册表设置。不确定安装后是否会剪切它,但是否需要权限。对我来说,它解决了 WebSocket 在 WPF 中的 WebBrowser 控件内不可用的问题。
C# webbrowser Ajax 调用
I liked the (C#) code in the following which sets the registry settings for your app. Not sure if it will cut it after installation though if permissions are required. For me it solved an issue with WebSocket not being available inside a WebBrowser control in WPF.
C# webbrowser Ajax call
我遇到了同样的问题,这里的注册表答案不起作用。
我的程序的新版本中有一个浏览器控件,在 XP 上运行良好,但在 Windows 7(64 位)中失败。
旧版本可以在 XP 和 Windows 7 上运行。
浏览器中显示的网页使用一些奇怪的插件来显示旧的 SVG 地图(我认为它是一个 Java 小程序)。
事实证明,该问题与 Windows 7 中的 DEP 保护有关。
旧版本的 dotnet 2 没有在 exe 中设置 DEP 必需标志,但从 dotnet 2、SP 1 开始,它就这样做了(是的,编译行为以及运行时行为) exe 的变化取决于你编译的机器,很好......)。
它记录在 MSDN 博客 NXCOMPAT 和 C# 编译器。引用:这无疑会让一些开发人员感到惊讶...下载框架服务包,重新编译,运行您的应用程序,然后您现在会收到 IP_ON_HEAP 异常。
将以下内容添加到 Visual 中的后期构建中Studio,关闭 exe 的 DEP,一切按预期工作:
/headers
将显示 exe 上的 DEP 设置。I had the same problem, and the registry answers here didn't work.
I had a browser control in new version of my program that worked fine on XP, failed in Windows 7 (64 bit).
The old version worked on both XP and Windows 7.
The webpage displayed in the browser uses some strange plugin for showing old SVG maps (I think its a Java applet).
Turns out the problem is related to DEP protection in Windows 7.
Old versions of dotnet 2 didn't set the DEP required flag in the exe, but from dotnet 2, SP 1 onwards it did (yep, the compiling behaviour and hence runtime behaviour of exe changed depending on which machine you compiled on, nice ...).
It is documented on a MSDN blog NXCOMPAT and the C# compiler. To quote : This will undoubtedly surprise a few developers...download a framework service pack, recompile, run your app, and you're now getting IP_ON_HEAP exceptions.
Adding the following to the post build in Visual Studio, turns DEP off for the exe, and everything works as expected:
/headers
will display the DEP setting on a exe.关于白鹰接受的答案。
我只是想增加一些实践经验。只是想添加评论,但 SO 抱怨它太长了。
基本上,如果没有安装 IE 9,注册表开关 FEATURE_BROWSER_EMULATION 将根本不起作用。
例如,我今天的经历是,我试图让 .net webcontrol 在 IE10 模式下工作,因为我尝试渲染的一个 html 无法在 VS2012 下与 .netControl 一起工作,甚至当我将 html 加载到 IE8 时也无法工作直接,CSS仍然无法正确渲染(即使在我说允许阻止的内容之后)。但我在朋友的 win 8 机器上用 IE10 测试了相同的 html。这就是为什么我尝试将 .net webControl 设置为 IE 10 模式但一直失败...
现在我想这是因为我的 win 7 机器只安装了 IE8,所以无论我为 FEATURE_BROWSER_EMULATION 开关设置哪个值(值为IE9、IE10 IE11),它根本不起作用!
然后我在我的 win 7 机器上下载并安装了 IE 10。还是不行,然后我添加了 FEATURE_BROWSER_EMULATION,它开始工作了!
我还注意到,无论我设置哪个值,甚至默认将其设置为值 0,webControl 仍然使用 IE 10 模式,这对我来说仍然有效。
总结一下,
如果您安装了 IE X,但希望您的 .Net webControl 在 IE (X+N) N>0 modo 下工作,您需要做两件事:
转到 MS 网站并访问 MS 网站。在您的计算机上下载并安装 IE (X+N),
安装后您需要重新启动。
应用怀特霍克的答案。
基本上:
要使用注册表控制此功能的值,请将可执行文件的名称添加到以下设置,并设置值以匹配所需的设置。
Windows Internet Explorer 8 及更高版本。 FEATURE_BROWSER_EMULATION 功能定义 Internet Explorer 的默认模拟模式并支持以下值。
值 说明
11001 (0x2AF9 Internet Explorer 11。网页在 IE11 中显示
边缘模式,无论 !DOCTYPE 指令如何。
11000 (0x2AF8) IE11。包含基于标准的 !DOCTYPE 的网页
指令在 IE11 边缘模式下显示。 IE11 的默认值。
10001 (0x2711) Internet Explorer 10。网页在 IE10 中显示
标准模式,无论 !DOCTYPE 指令如何。
10000 (0x02710) Internet Explorer 10。包含以下内容的网页
基于标准的 !DOCTYPE 指令显示在 IE10 标准中
模式。 Internet Explorer 10 的默认值。
9999 (0x270F) Windows Internet Explorer 9。网页显示在
IE9 标准模式,无论 !DOCTYPE 指令如何。
9000 (0x2328) Internet Explorer 9. 包含以下内容的网页
基于标准的 !DOCTYPE 指令在 IE9 模式下显示。
Internet Explorer 9 的默认值。
重要提示在 Internet Explorer 10 中,包含以下内容的网页
基于标准的 !DOCTYPE 指令显示在 IE10 标准中
模式。
8888 (0x22B8) 网页以 IE8 标准模式显示,
无论 !DOCTYPE 指令如何。
8000 (0x1F40) 包含基于标准的 !DOCTYPE 指令的网页
在IE8模式下显示。 Internet Explorer 8 的默认值
重要 在 Internet Explorer 10 中,包含以下内容的网页
基于标准的 !DOCTYPE 指令显示在 IE10 标准中
模式。
7000 (0x1B58) 包含基于标准的 !DOCTYPE 指令的网页
以 IE7 标准模式显示。应用程序的默认值
托管 WebBrowser 控件。
完整参考此处
Regarding whitehawk's accepted answer.
I am just trying to add a bit hands on experience. Was just trying to add a comments, but SO complains it's too long.
Basically, without IE 9 installed, the registry switch FEATURE_BROWSER_EMULATION won't work AT ALL.
For example, my own experience today I was trying to get the .net webcontrol to work with IE10 mode because one html I am trying to render won't work with .netControl under VS2012, and not even work when I load the html to IE8 directly, still css won't render properly(even after I say allow blocked content). But I have tested the same html ok with IE10 on a friend's win 8 machine. That's why I am trying to set the .net webControl to IE 10 mode but just keeps failing...
Now I figured this is bcos my win 7 machine only have IE8 installed, so regardless which value I set to the FEATURE_BROWSER_EMULATION switch(value to IE9, IE10 IE11), it just won't work AT ALL !
Then I downloaded and installed IE 10 on my win 7 machine. Still it won't work, then I added the FEATURE_BROWSER_EMULATION, it started working !
Also I noticed regardless which value I set , even set it to value 0 by default, the webControl is still using IE 10 mode which still works for me.
So to summarise,
If you have IE X installed but you want your .Net webControl to work under IE (X+N) N>0 modo, TWO things you need to do:
Go to MS website & download and install IE (X+N) on your machine,
you will need to reboot after installation.
apply whitehawk's answer.
Basically:
To control the value of this feature by using the registry, add the name of your executable file to the following setting and set the value to match the desired setting.
Windows Internet Explorer 8 and later. The FEATURE_BROWSER_EMULATION feature defines the default emulation mode for Internet Explorer and supports the following values.
Value Description
11001 (0x2AF9 Internet Explorer 11. Webpages are displayed in IE11
edge mode, regardless of the !DOCTYPE directive.
11000 (0x2AF8) IE11. Webpages containing standards-based !DOCTYPE
directives are displayed in IE11 edge mode. Default value for IE11.
10001 (0x2711) Internet Explorer 10. Webpages are displayed in IE10
Standards mode, regardless of the !DOCTYPE directive.
10000 (0x02710) Internet Explorer 10. Webpages containing
standards-based !DOCTYPE directives are displayed in IE10 Standards
mode. Default value for Internet Explorer 10.
9999 (0x270F) Windows Internet Explorer 9. Webpages are displayed in
IE9 Standards mode, regardless of the !DOCTYPE directive.
9000 (0x2328) Internet Explorer 9. Webpages containing
standards-based !DOCTYPE directives are displayed in IE9 mode.
Default value for Internet Explorer 9.
Important In Internet Explorer 10, Webpages containing
standards-based !DOCTYPE directives are displayed in IE10 Standards
mode.
8888 (0x22B8) Webpages are displayed in IE8 Standards mode,
regardless of the !DOCTYPE directive.
8000 (0x1F40) Webpages containing standards-based !DOCTYPE directives
are displayed in IE8 mode. Default value for Internet Explorer 8
Important In Internet Explorer 10, Webpages containing
standards-based !DOCTYPE directives are displayed in IE10 Standards
mode.
7000 (0x1B58) Webpages containing standards-based !DOCTYPE directives
are displayed in IE7 Standards mode. Default value for applications
hosting the WebBrowser Control.
Full ref here