一.问题的提出
下面有张图,里面一个窗口是用IE9打开某网站,另一个窗口是用Winform+WebBrowser打开同样的网站,有意思的事情出现了。
在IE9窗口中,这个网站左边菜单树无法显示,原因是IE9使用的技术较新,而网站使用的技术较旧,未能及时同步更新到支持IE9所致。该如何办呢? 微软在IE9中提供一个兼容性视图功能,只要一点击兼容性视图就可以兼容旧版本浏览器的网站。
也就是说,这个兼容模式就是IE7的模式。
又查了些ms资料,发现这个兼容性视图在IE8时首次引入,在IE9,IE10中都将继续支持。
再翻回来看Winform+WebBrowser这个窗口,它打开同样的网站却能显示左边菜单树,这样看来,似乎WebBrowser不用设置就默认自动打开了兼容性视图模式。
现在就去仔细查一下权威资料,核实一下两个问题:
二.查询结果 1.webbrowser调用的就是本机IE9,并且webbrowser默认就是运行在IE7 mode下,除非你改变它. 发现一个msdn的帖子,明确表示webbrowser调用的就是本机IE9,并且webbrowser默认就是运行在IE7 mode下,除非你改变它。 摘几句: 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. 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.WPF webbrowser control using IE7 instead of IE9 摘抄几句: 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./weblog/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version
5.WebBrowser and CSS3 ? 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]
6.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 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) 9000 (0x2328) 8888 (0x22B8) 8000 (0x1F40) 7000 (0x1B58)
ok, 言尽至此,无话可说了! |
|