Question

Can someone provide some background on the TWebBrowser component with regards to HTML/CSS standards? I am puzzled why it is that despite the fact that I am using Windows 7, with IE 8 installed, that I get different rendered results when displaying a HTML file in IE8 versus what I see when the same HTML file is displayed within TWebBrowser. For instance, pseudo elements p:before and p:first-letterare totally ignored in the CSS file when the HTML file is viewed in TWebBrowser (Delphi 7), yet they are honored when the same HTML file is viewed in IE8.

Is the SHDOCVW.DLL perhaps so old that I am in affect getting IE3 rendering? I'm trying to wrap my head around why IE8 frequently renders HTML considerably different than what one gets when using TWebBrowser.

Was it helpful?

Solution

IE8 renders pages running within instances of the WebBrowser control in IE7 Standards Mode by default. The difference that you see is therefor based on the difference of the IE8 & IE7 standard.

When an executable loads an instance of the WebBrowser control it scans the registry to check whether the executable wants IE7 Standards or IE8 Standards mode.

WebBrowser Control Rendering Modes in IE8(deprecated)
WebBrowser Control Rendering Modes in IE8(Updated)

To run a WebBrowser control in IE7 Standards Mode, insert the following values into the registry:

[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION] 
"MyApplication.exe" = dword 7000 (Hex: 0x1B58)

To run in IE8 Standards Mode insert the following registry value:

 [(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION] 
"MyApplication.exe" = dword 8000 (Hex: 0x1F40)

In both of these instances, MyApplication.exe should be replaced with the name of the executable that will be running WebBrowser controls in a specified mode.


That much said, you can avoid fiddling with the registry all together.

Pages hosted in a WebBrowser control can override rendering settings by using the X-UA-Compatible meta tag to specify a rendering mode.

for example, to force IE8 TWebBrowser control to render site in IE8 standard use:

<META http-equiv="X-UA-Compatible" content="IE=8">

This can be done globally via a host-header or as a per-document edit.

the Meta tag solution might be deprecated, I would suggest you follow the registry steps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top