How to programmatically turn off quirks mode in IE8 WebBrowser control?
Asked Answered
H

5

20

I want to use IE8 as a WebBrowser control in a C# application. How can I disable "quirks mode" and force IE into standards compliance (as far as it is implemented)?

Hellespont answered 14/3, 2009 at 21:11 Comment(0)
E
14

I think the issue you're facing is described in IEBlog: WebBrowser Control Rendering Modes in IE8:

While webmasters can easily alter their site to render properly in the new version of IE, many software vendors do not have the resources to instantly push out new versions of their applications with updated internal pages. In order to ensure that these existing applications remain in working order, IE8 renders pages running within instances of the WebBrowser control in IE7 Standards Mode by default.

Here I should note that the comments on the page say the above is incorrect, and that "IE8 renders pages running within instances of the WebBrowser control in IE7 Strict Mode OR Quirks mode by default, depending on the page's doctype."

The solution is as follows:

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.

...

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

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_NATIVE_DOCUMENT_MODE]

"MyApplication.exe"=dword:13880

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.

So it sounds like the "programmatic" solution is to write a key in the registry saying you want IE8 Standards mode for WebBrowser controls in your specific application.

Eirena answered 14/3, 2009 at 21:37 Comment(2)
It would be better if there was a property to set on the browser control - this would be easer when the user does not have registry permissions, though this is less of an issue under HKEY_CURRENT_USER (the key also works in the equivalent point under HKEY_LOCAL_MACHINE).Norvin
FYI, FEATURE_NATIVE_DOCUMENT_MODE has been superceeded by FEATURE_BROWSER_EMULATION.Hoboken
A
25

If you don't want to use the registry key technique, you could insert the following tag:

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

The "content" attribute forces rendering in various modes.

Apraxia answered 20/3, 2009 at 0:46 Comment(5)
The above tag was striped from my post. Just add the opening angle bracket.Apraxia
Just surround your meta tag with backticks, like this: <meta http-equiv="X-UA-Compatible" content="IE=8"/>.Was
I think the question was really how to force the browser itself (he's using a asp.net WebBrowser control to "create" a browser in his application). Changing this meta parameter or the doc type (which is the usual solution - see en.wikipedia.org/wiki/Quirks_mode) is something that you do at the site level... What is explained by Daniel is how to override any site's setting to a standard non-quirks mode. I think this was properly explained by Daniel.Inquest
My experience is that there are subtle differences: using the Registry way, IE8 embedded is just like IE8. Using the meta tag, there is still some IE7-ish rendering.Norvin
@Apraxia I must ask, is this the one and only, Elijah Manor?Bifoliolate
E
14

I think the issue you're facing is described in IEBlog: WebBrowser Control Rendering Modes in IE8:

While webmasters can easily alter their site to render properly in the new version of IE, many software vendors do not have the resources to instantly push out new versions of their applications with updated internal pages. In order to ensure that these existing applications remain in working order, IE8 renders pages running within instances of the WebBrowser control in IE7 Standards Mode by default.

Here I should note that the comments on the page say the above is incorrect, and that "IE8 renders pages running within instances of the WebBrowser control in IE7 Strict Mode OR Quirks mode by default, depending on the page's doctype."

The solution is as follows:

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.

...

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

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_NATIVE_DOCUMENT_MODE]

"MyApplication.exe"=dword:13880

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.

So it sounds like the "programmatic" solution is to write a key in the registry saying you want IE8 Standards mode for WebBrowser controls in your specific application.

Eirena answered 14/3, 2009 at 21:37 Comment(2)
It would be better if there was a property to set on the browser control - this would be easer when the user does not have registry permissions, though this is less of an issue under HKEY_CURRENT_USER (the key also works in the equivalent point under HKEY_LOCAL_MACHINE).Norvin
FYI, FEATURE_NATIVE_DOCUMENT_MODE has been superceeded by FEATURE_BROWSER_EMULATION.Hoboken
K
4

The last I heard was that IE8 would use standards mode by default. Are you seeing an actual problem with the latest beta version? Are you sure it's rendering in quirks mode to start with, without a user explicitly hitting the compatibility view button?

Kibitzer answered 14/3, 2009 at 21:17 Comment(2)
I think the WebBrowser control and the standalone browser behave differently in this case.Eirena
Looks like it, yes. Will edit question title to make it more specific.Kibitzer
G
3

Please note there have been some changes since the beta, the registry keys have been renamed etc. Read more here.

Gismo answered 18/3, 2009 at 17:35 Comment(0)
R
0

This has actual code to programmatically do this and handles up to IE11 so far:

C# webbrowser Ajax call

Rapier answered 30/12, 2013 at 23:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.