做了一個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開啟。

建議只做本地測試使用。儘量提高網站自身的相容性才是王道。

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.