`
xiaojiit
  • 浏览: 134183 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

WebBrowser与IE的关系,如何设置WebBrowser工作在IE9模式下?

    博客分类:
  • C#
阅读更多

0、此方法经本人测试,确实可用!(只测试了IE9)。

 

一.问题的提出


偶然发现,Winform里的WebBrowser和IE实际安装的版本似乎并不同步,很有趣!

 

下面有张图,里面一个窗口是用IE9打开某网站,另一个窗口是用Winform+WebBrowser打开同样的网站,有意思的事情出现了。

 

在IE9窗口中,这个网站左边菜单树无法显示,原因是IE9使用的技术较新,而网站使用的技术较旧,未能及时同步更新到支持IE9所致。该如何办呢?

微软在IE9中提供一个兼容性视图功能,只要一点击兼容性视图就可以兼容旧版本浏览器的网站。
 


引用MSDN “To overcome potential compatibility issues, Internet Explorer supports a feature called Compatibility View that allows users to display troublesome pages in IE7 mode. “ URL: http://msdn.microsoft.com/en-us/library/dd567845(v=VS.85).aspx

也就是说,这个兼容模式就是IE7的模式。

 

又查了些ms资料,发现这个兼容性视图在IE8时首次引入,在IE9,IE10中都将继续支持。

 

再翻回来看Winform+WebBrowser这个窗口,它打开同样的网站却能显示左边菜单树,这样看来,似乎WebBrowser不用设置就默认自动打开了兼容性视图模式。

 

现在就去仔细查一下权威资料,核实一下两个问题:
1.Webbrowser与IE到底是什么关系?是否确实用ie内核, 是否本质上和360安全浏览器,傲游浏览器和腾讯TT等IE内核浏览器相同。
2.Webbrowser是否使用兼容浏览模式,以及这个模式是否能改?

 

二.查询结果

1.webbrowser调用的就是本机IE9,并且webbrowser默认就是运行在IE7 mode下,除非你改变它.

发现一个msdn的帖子,明确表示webbrowser调用的就是本机IE9,并且webbrowser默认就是运行在IE7 mode下,除非你改变它。
How to make c# WebBrowser equivalent to IE browser  
http://social.msdn.microsoft.com/Forums/en/winforms/thread/2ed65b9d-c601-4ca8-bde1-64584fc87515

摘几句:
Wow first post with such bold claim without any source backing up. You probably should read the IE SDK (the manual you need to read if you want to use the webbrowser control) or dig through the IE programming forums (that's the place others often go when they are stuck on IE programming) if you want to use the webbrowser control.

Webbrowser is a wrapper around IE APIs. There is no such thing as multiple versions of IE coexisting on the same computer. You will always get the one and only version of IE installed on the computer from webbrowser control.

There are many, many documented setting differences between default IE and webbrowser. Basically you don't have to opt out new features in webbrowser that may break your app (the Visual Studio team learned a hard lesson here, when IE8 breaks Visual Studio's wizards) , you have to write code to opt in, unless the improvement is security related. That means the webbrowser will run in IE7 mode unless you change the mode in feature control.

Note some web site declare their requirement of IE7 or IE8 mode. It may not be wise to force the IE9 mode. 

 

2.微软新闻组的一个帖子,Webbrowser Control without IE,里面明确提到,不装IE,无法用webbrowser.
http://groups.google.com/group/microsoft.public.vb.controls/browse_thread/thread/7575bd25e0730ded/aa40f3dfc799407d?lnk=gst&q=WebBrowser+ie#aa40f3dfc799407d

IE must be installed on the machine for you to use Webbrowser Control.

Internet Explorer MUST be installed to use the WebBrowser control.  There are simply no ifs, ands, or buts about it.  How can you expect to use IE functionality if IE is not installed?

 

3.如何设置WebBrowser在IE9 mode下工作呢?
答曰:需要修改注册表,具体看下面4,5,6,尤其6最全面,可以光看6。

 

4.WPF webbrowser control using IE7 instead of IE9
http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/4431908e-1869-4435-bcea-a3ec0820edfb

摘抄几句:
How do I make it so the WPF WebBrowser control will use IE9 as the browser engine instead of IE7?
I have some HTML that is rendering differently in the WebBrowser control than in the IE9 browser. When I run the following javascript in the WebBrowser, the result is "7". as in IE7.

I found an article by Rick Strahl that describes registry settings that will get the WebBrowser to use IE9. But I would like to avoid that. And I am interested to know how IE7 comes about being used.http://www.west-wind.com/weblog/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version
回答:You want to avoid the only documented way to set document compatibility mode for webbrowser hosts? Why?

 

5.WebBrowser and CSS3 ?
http://social.msdn.microsoft.com/Forums/en-AU/winforms/thread/1b656af7-bda9-47d9-8f9a-1d886d3688ca
Web browser control by default runs in compatibility mode unless you set the feature browser emulation registry key. The fact that IE9 is able to render CSS3 correctly and browser control is not seems to suggest browser control is not running in IE9 standards mode.

You'll need to set Browser emulation feature key (FEATURE_BROWSER_EMULATION) described at this link http://msdn.microsoft.com/en-us/library/ee330730%28v=vs.85%29.aspx

You can use 9000 value, unless you want to force IE 9 standards mode for all pages. In case of later, you need to use 9999.

hklm

If hklm and 64bit machine used, you need to check is Wow6432Node needs to be changed.

And finally you need to add process name hosting browser control as value name in the registry key.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION]
"prevhost.exe"=dword:00001f40
"sllauncher.exe"=dword:00001f40
"WindowsFormsApplication1.exe"=dword:0000270f

 

6.Web Browser Control – Specifying the IE Version 
http://www.west-wind.com/weblog/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version

I use the Internet Explorer Web Browser Control in a lot of my applications to display document type layout. HTML happens to be one of the most common document formats and displaying data in this format – even in desktop applications, is often way easier than using normal desktop technologies.

One issue the Web Browser Control has that it’s perpetually stuck in IE 7 rendering mode by default. Even though IE 8 and now 9 have significantly upgraded the IE rendering engine to be more CSS and HTML compliant by default the Web Browser control will have none of it. IE 9 in particular – with its much improved CSS support and basic HTML 5 support is a big improvement and even though the IE control uses some of IE’s internal rendering technology it’s still stuck in the old IE 7 rendering by default.

This applies whether you’re using the Web Browser control in a WPF application, a WinForms app, a FoxPro or VB classic application using the ActiveX control. Behind the scenes all these UI platforms use the COM interfaces and so you’re stuck by those same rules.

Feature Delegation via Registry Hacks
Fortunately starting with Internet Explore 8 and later there’s a fix for this problem via a registry setting. You can specify a registry key to specify which rendering mode and version of IE should be used by that application. These are not global mind you – they have to be enabled for each application individually.

There are two different sets of keys for 32 bit and 64 bit applications.

32 bit:

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

Value Key: yourapplication.exe

64 bit:

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

Value Key: yourapplication.exe

The value to set this key to is (taken from MSDN here) as decimal values:

9999 (0x270F) 
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.

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.

7000 (0x1B58) 
Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.

 

ok, 言尽至此,无话可说了!

 

 

文章来源:http://www.cnblogs.com/liuzhendong/archive/2012/03/21/2410107.html

分享到:
评论

相关推荐

    C# WebBrowser 任意切换IE版本

    例如,若要让`WebBrowser`控件使用IE9的核心,可以创建一个名为`yourApp.exe`的键,并将其值设为9999。这里的"9999"表示使用最高可用的IE版本。如果要指定具体版本,如IE11,可以设置值为11001。 `GroupBox.cs`可能...

    Winform测试WebBrowser控件对应的IE版本

    与B/S(浏览器/服务器)架构的网页应用不同,C/S应用中的WebBrowser控件可以直接利用本地系统资源,无需通过网络加载网页,这使得它在某些情况下比直接打开浏览器更加高效。 要了解WebBrowser控件所使用的IE版本,...

    IE WebBrowser编程技巧

    WebBrowser与MSHTML 直接在WebBrowser中写HTML字符串 在webbrowser中查找字符串并定位 把图片拷贝进剪贴板 IHTMLDocument的ExecCommand 处理事件的Internet Explorer中的DOM 禁止WebBrowser右键弹出菜单 禁止...

    如何对webbrowser和IE编程

    在编程领域,WebBrowser控件和Internet Explorer(IE)编程主要涉及到如何利用这些工具与Web交互,实现网页浏览、数据获取、自动化操作等功能。本文将详细介绍WebBrowser控件的使用和IE编程的基础知识。 首先,...

    IEWebBrowser组件用法

    IEWebBrowser组件是微软在ActiveX技术基础上提供的一种控件,主要用于在Windows应用程序中嵌入Web浏览器的功能。它允许开发者在桌面应用中实现网页浏览、交互以及与Web内容的集成。这篇文档将深入探讨IEWebBrowser...

    vfp WebBrowser(支持内核是ie 和 edge)

    在VFP中添加WebBrowser控件非常简单,只需在表单设计模式下从工具箱拖拽WebBrowser控件到表单上即可。设置控件的属性,如`Visible`来决定是否显示,`Url`来指定要加载的网页地址。 2. **响应网页按钮点击** 要...

    设置使用webbrowser的软件使用的IE版本

    BROWSER_EMULATION`或`HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION`下的键值,可以设定控件的行为模式,如模拟IE8、IE9、IE11等。 设置过程通常包括...

    C# WebBrowser 切换IE版本

    C# WebBrowser 任意切换IE版本,实惠WebBrowser的IE版本解决兼容性问题

    iewebbrowser组件的execwb方法

    `WebBrowser.ExecWB`是`iewebbrowser`组件中的一个重要方法,用于模拟用户在浏览器中的各种操作行为,如打开新页面、保存页面等。该方法提供了一种简便的方式来执行常见的浏览器命令,使得开发者无需深入了解底层API...

    webbrowser仿ie浏览器缩放功能绝对完美

    - IE7 和 IE9 最大支持缩放至1000%。 - IE8 最大支持缩放至9999%。 因此,在编写代码时需要注意这些差异,确保应用程序能够在不同版本的IE中正常运行。 #### 五、结语 通过上述方法,我们可以在C#应用中实现...

    Delphi禁止WebBrowser弹出IE的对话框

    在大多数情况下,这是与用户交互的一种方式,但在自动化或无用户交互的应用场景中,这些弹窗会成为问题。 要禁止WebBrowser组件弹出对话框,我们可以通过实现`IWebBrowser2`接口的事件处理来拦截JavaScript的警框。...

    C# winform webbrowser指定内核为IE.reg

    C# winform webbrowser如何指定内核为IE C# winform webbrowser如何指定内核为IE

    C# webbrowser 多IE版本 11,10,9,8 可调整

    在"C# webbrowser 多IE版本 11,10,9,8 可调整"这个主题中,我们将深入探讨如何在C#应用中实现对不同IE版本的支持,特别是如何动态地在IE11、IE10、IE9和IE8之间进行切换。 首先,`WebBrowser`控件默认基于系统安装...

    简单IE浏览器(C# webbrowser的使用)

    **简单IE浏览器(C# WebBrowser控件的使用)** 在.NET框架中,C#提供了一个内置的`WebBrowser`控件,它允许开发者在应用程序中嵌入一个浏览器引擎,实现类似Internet Explorer的功能。本篇文章将深入探讨如何使用C#的...

    IE WebBrowser控件基本使用

    在Windows编程中,IE WebBrowser控件是一个非常重要的组件,它允许开发者在应用程序中嵌入一个Web浏览器的功能。这个控件基于Microsoft Internet Explorer的内核,使得开发者可以实现浏览网页、执行JavaScript、与...

    VC中使用Webbrowser控件相关的安全设置

    它是基于Internet Explorer(IE)的引擎,因此它的安全性与IE的设置密切相关。默认情况下,WebBrowser控件会遵循用户系统的Internet Explorer安全区域设置,如受限站点、Internet、本地Intranet和受信任的站点等。 ...

    验证码 填表 IE webbrowser

    在IT领域,验证码填表和IE WebBrowser控件是两个重要的概念,它们在网页交互和自动化处理中扮演着关键角色。下面将详细解释这两个概念及其相关的知识点。 验证码(CAPTCHA)全称为“Completely Automated Public ...

Global site tag (gtag.js) - Google Analytics