Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I turn off Compatibility View on the IE WebBrowserControl in a WinForms app?

In my WinForms app, if I use a WebBrowser control, it seems to be forced into compatibility mode. How can I disable this, and make it behave the same as standalone IE does on my machine when browsing the same site?

  • I do not want to make registry changes. I want everything to be contained within my app.
  • The website I'm loading is not mine, so I do not have the ability to make changes to it (unless they can be done programmatically from within my app).
like image 217
Danny Tuppeny Avatar asked Jul 16 '11 11:07

Danny Tuppeny


3 Answers

There is no way to do this other than configuring the following registry settings:

HKLM\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

or if it's a 32 bit app on 64 bit Windows:

HKLM\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION`

These settings aren't surfaced in the WebBrowser control.

For more information please see:

What IE compatibility mode does the webbrowser control use?

In case the link dies:

You create a DWORD value matching the name of your executable and set this value to one of:

7000: Pages containing standards-based <!DOCTYPE> directives are displayed in IE7 mode.
8000: Pages containing standards-based <!DOCTYPE> directives are displayed in IE8 mode
8888: Pages are always displayed in IE8 mode, regardless of the <!DOCTYPE> directive. (This bypasses the exceptions listed earlier.)
9000: Use IE9 settings!
9999: Force IE9

For example:

enter image description here

From my own experiments with IE9:

  • 9000 - inherits the compatibility mode set in IE9's global compatibility mode setting. i.e.: enter image description here

  • 9999 - forces IE9 out of compatibility mode in the host application regardless of the globally configured compatibility mode setting

Your application would probably need to detect which underlying IE version is available to determine which value to use:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version

or if it's a 32 bit app on 64 bit Windows:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Version

There's also this older article from when IE8 came out which is worth a look:

More IE8 Extensibility Improvements

You can also configure these settings on a per user basis under:

HKCU\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
like image 140
Kev Avatar answered Nov 20 '22 02:11

Kev


Although it's not what you asked, if you own the site you can add the following into the head section of the html.:

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

See: http://msdn.microsoft.com/en-us/library/cc288325(v=vs.85).aspx

like image 41
IndustrialControlFreak Avatar answered Nov 20 '22 01:11

IndustrialControlFreak


Here is the skinny of the problem: If a user enables Compatibility View in IE8 then it will override all page directives. So any page or server variable you attempt to use will fail to prevent IE from switching to Compatibility View if the user has turned on this feature in IE. Most people think page directives or some kind of secret header server variable will fix the site. Nope. None of these solutions work if the setting has been manually overridden. I know, it is just not cool. So the following will work only if the user has not enabled the compatibility view feature.

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

To clarify the steps to change this in the registry edit the key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

Then add a new DWORD called iexplore.exe. To do this right-click the key and select New > DWORD. Give that DWORD the decimal value of 9999. This will make all sites render without compatibility view. To enable Compatibility View again delete this DWORD. Also if you wish to automate this change and run a batch script on your system check out Michal M's script.

https://gist.github.com/michal-m/1853315

like image 5
mbokil Avatar answered Nov 20 '22 00:11

mbokil