今天在調試程序的時候,須要使用C#的客戶端遠程登陸一個Web頁面,用到了WebBrowser控件。可是卻發現了一件很神奇的事情:瀏覽器
當前瀏覽器使用的內核,能夠經過訪問下面這個網站獲取:http://ie.icoa.cn/app
個人IE版本爲IE8,在使用IE登陸頁面的時候,使用的內核是IE8,登陸該網站的截圖以下:less
可是當我用WebBrowser登陸該頁面時,顯示使用的內核倒是IE7:編輯器
上圖的程序是一個測試程序,僅包含一個WebBrowser,這個程序的名稱是TestWebBrowser.exe。能夠發現,雖然同爲Trident內核,但在WebBrowser控件中使用的內核版本卻與IE不同,這讓我感到疑惑。由於我要登陸的頁面是針對IE8以上版本開發的,所以我須要嘗試讓程序內的WebBrowser以IE8的內核登陸網頁。ide
在網上找了一些資料後,我發現能夠經過下面這個辦法來解決:測試
一、在開始菜單內輸入「regedit.exe」,進入註冊表編輯器網站
二、找到註冊表項:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATIONui
三、在右側空白區域內單擊鼠標右鍵,點擊【新建】→【DWORD(32-位)值】翻譯
四、新建的項取名爲TestWebBrowser.exe,編輯值時,選擇基數「十進制」,填寫數值數據,這裏填寫8888調試
五、這個時候再進入Debug目錄下生成好的TestWebBrowser,能夠看到登陸的內核版本變成IE8了!
須要注意的是,在VS內以調試的方法進入程序,打開的程序其實是TestWebBrowser.vshost.exe,並不能看到效果,必需要打開Debug目錄下的TestWebBrowser.exe,才能發現內核版本的改變。以前WebBrowser使用IE7內核的緣由,就是.NET中的WebBrowser控件默認使用了IE7兼容性模式來瀏覽網頁。
一一一一一一一一一分割線一一一一一一一一一
上面這個方法依靠修改註冊表來完成WebBrowser使用內核的變動,不過光知道新建一個註冊表項並把值設置爲「8888」還遠遠不夠,本着「知其然還要知其因此然」的想法,我查閱了相關的MSDN頁面:https://msdn.microsoft.com/en-us/library/ee330730%28v=vs.85%29.aspx
這個頁面的標題是:Internet Feature Controls (B..C),即互聯網功能控制,咱們要找的章節是「Browser Emulation」(瀏覽器仿真)。原來自從IE8之後,在註冊表中添加了FEATURE_BROWSER_EMULATION功能,這個功能是用來定義IE默認的仿真模式。
這個功能在註冊表中的位置以下:
該註冊表項的各可能取值描述以下(原文見MSDN,純手工翻譯)
7000 (0x1B58)
Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control.
包含標準!DOCTYPE指令的頁面將會以IE7兼容模式打開。WebBrowser控件的默認值。
8000 (0x1F40)
Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8
Important In Internet Explorer 10, Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
包含標準!DOCTYPE指令的頁面將會以IE8兼容模式打開,IE8瀏覽器的默認值。對於IE10來講,包含標準!DOCTYPE指令的頁面會以IE10兼容模式打開。
8888 (0x22B8)
Webpages are displayed in IE8 Standards mode, regardless of the declared !DOCTYPE directive. Failing to declare a !DOCTYPE directive causes the page to load in Quirks.
不管是否聲明!DOCTYPE指令,頁面以IE8兼容模式打開。對於未正確聲明!DOCTYPE指令的頁面,將會以怪異模式(quirks mode)加載。
9000 (0x2328)
Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
Important In Internet Explorer 10, Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
IE9,包含標準!DOCTYPE指令的頁面將會以IE9兼容模式打開,IE9瀏覽器的默認值。對於IE10來講,包含標準!DOCTYPE指令的頁面會以IE10兼容模式打開。
9999 (0x270F)
Windows Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the declared !DOCTYPE directive. Failing to declare a !DOCTYPE directive causes the page to load in Quirks.
IE9,不管是否聲明!DOCTYPE指令,頁面以IE9兼容模式打開。對於未正確聲明!DOCTYPE指令的頁面,將會以怪異模式(quirks mode)加載。
10000 (0x02710)
Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10.
IE10,包含標準!DOCTYPE指令的頁面將會以IE10兼容模式打開,IE10瀏覽器的默認值。
10001 (0x2711)
Internet Explorer 10. Webpages are displayed in IE10 Standards mode, regardless of the !DOCTYPE directive.
IE10,不管是否聲明!DOCTYPE指令,頁面以IE10兼容模式打開。
11001 (0x2AF9)
IE11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 edge mode. Default value for IE11.
IE11,包含標準!DOCTYPE指令的頁面將會以IE11兼容模式打開,IE11瀏覽器的默認值。
11000 (0x2AF8)
Internet Explorer 11. Webpages are displayed in IE11 edge mode, regardless of the declared !DOCTYPE directive. Failing to declare a !DOCTYPE directive causes the page to load in Quirks.
IE11,不管是否聲明!DOCTYPE指令,頁面將會以IE11的edge模式打開。對於未正確聲明!DOCTYPE指令的頁面,將會以怪異模式(quirks mode)加載。
END