Winform WebBrowser引用IE版本问题

时间:2022-05-06 23:51:30

  做了一个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

Winform WebBrowser引用IE版本问题

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

建议只做本地测试使用。尽量提高网站自身的兼容性才是王道。

IE各版本的值如下:

  • 11001 (0x2EDF) Internet Explorer 11. Webpages are displayed in IE11 Standards mode, regardless of the !DOCTYPE directive

  • 11000 (0x2AF8) :Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode

  • 10000 (0x2710) :Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.

  • 10001 (0x2AF7) :Internet Explorer 10. Webpages are displayed in IE10 Standards mode, regardless of the !DOCTYPE directive.

  • 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.