Shortly before the development of a project, is the use of WebBrowser as the shell, loading the Web page, because the Web page is developed using HTML5, when the page through WebBrowser loading, HTML5 features
Can not be displayed properly, and through IE browser Open when the normal display, after study found that WebBrowser by default is IE7 compatibility mode to render, so HTML5 features can not be displayed. So
How do we change the rendering mode of the WebBrowser kernel?
Internet Explorer Architecture
First look at the entire architecture of IE, such as
ShDocVw and the following is the content of WebBrowser, and browser UI and ie own some of the unique features do not belong to WebBrowser all. Of course, it's not about making your own IE-based browser.
You have to use WebBrowser, we can use MSHTML directly to control and draw the DOM, skipping WebBrowser.
Many software are embedded in the IE WebBrowser control (that is, MSHTML.dll) to display the Web page, when the user machine upgrade to an IE version, WebBrowser control will also be upgraded to the corresponding
The rendering engine corresponding to the IE version. To ensure that these applications that use the WebBrowser control can work as before, the WebBrowser controls of different versions of IE are used by default IE7
Rendering mode.
Set WebBrowser Rendering Mode
As below, a WebBrowser load a Web page for W3school, which contains a video tag, ie is rendered using IE7 compatibility mode by default and is expected to be unavailable for video.
<Grid> <WebBrowser Source="Http://www.w3school.com.cn/tiy/t.asp?f=html5_video_dom"></ WebBrowser> </Grid> |
The results are as follows:
Tip "Your Browser does not support HTML5 video", indicating that the default in WebBrowser is not in the local machine IE version corresponding to the mode of rendering, next we modify the registry, to enable
WebBrowser supports HTML5 properties, which are rendered using a higher IE version of the kernel.
Modifying registry settings WebBrowser the rendering mode of the kernel
1, installation package in the installation, the first from the registration table to obtain the system's IE version number, if it is under IE 8, skip this logic. The acquisition of the version number can be read from here:
32-bit system: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\version
64-bit system: Hkey_local_machine\software\wow6432node\microsoft\internet explorer\version
2. Create the key value in the registry location, the key is the name of the program that uses the Web browser control, such as WebBrowser.exe (no full path required, full file name with extension is OK), value
Gets the version value for the first step. MSDN shows a total of 9 enumeration values (Http://msdn.microsoft.com/en-us/library/ee330730%28v=vs.85%29.aspx#browser_emulation), which can be based on the actual
settings, such as Decimal 9. The registry location is:
32-bit system: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\main\featurecontrol\feature_browser_emulation
64-bit system: Hkey_local_machine\software\wow6432node\microsoft\internet Explorer\main\featurecontrol\feature_browser_ EMULATION
Sample code
var exename = process.getcurrentprocess (). ProcessName + ". exe"; var HKLM = Registry.localmachine; Try { var lmrun = HKLM. OpenSubKey (@ "Software\Microsoft\Internet Explorer\Main\FeatureControl feature_browser_emulation ", true); if (lmrun != null) { Try { Lmrun.setvalue (EXEName, 0x2710); set webbrowser call IE10 kernel to open } catch (Exception ex) { Console.Write (ex. Message); } } }
|
After modifying the registry, the following results are run:
The instructions are done!