WebBrowser引用IE版本问题,更改使用高版本IE

 做了一个Winform的项目。项目里使用了WebBrowser控件。以前一直都以为WebBrowser是直接调用的系统自带的IE,IE是呈现出什么样的页面WebBrowser就呈现出什么样的页面。其实并非如此。我的Winform程序加载了一个Web项目。这个项目对IE8一下的浏览器布局兼容不是太好。本机使用的是IE8,项目是.net4.0。用本机浏览器查看Web项目没有任何问题。可是调用Winform里的WebBrowser浏览Web项目页面却出现了布局问题。所以我就开始质疑到底WebBrowser是不是IE8的模式啊。于是打开IETester,从IE9一直到IE5都查看了一遍,发现最像WebBrowser布局呈现的是IE7模式下。在搜了一些相关资料原来WebBrowser使用的是IE的兼容模式进行浏览(IE7模式)。

  如何让WebBrowser引用IE 8 呢。可以通过注册表的新增键值实现

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

  在其中新增一个DWORD值。键值名称写入你的程序名,然后在数值数据填入1f40。也就是IE8

填写完毕后。到程序目录下打开就可以看到WebBrowser已经引用IE8模式了,这里要主意的是不要在VS打开。

 

下面是32位 64位系统需要修改的注册表地址 以及IE各版本的值
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.

posted @ 2018-02-28 16:48  幕三少  阅读(1301)  评论(2编辑  收藏  举报