33

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).
Danny Tuppeny
  • 40,147
  • 24
  • 151
  • 275
  • 2
    See also (http://stackoverflow.com/questions/4097593/how-to-put-the-webbrowser-control-into-ie9-into-standards) – Ian Boyd Jul 16 '11 at 13:09

4 Answers4

54

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
Kev
  • 118,037
  • 53
  • 300
  • 385
  • Wow, this really sucks. I tried Awesomium but it has real issues in the Visual Studio designer and crashes VS. I got into a nice loop where VS crashed upon loading my solution (because I had a control open, which had the Awesomium browser), so I just ripped it out in frustration. – Danny Tuppeny Jul 16 '11 at 12:59
  • 1
    Unfortunately that's just the way it is. – Kev Jul 16 '11 at 13:06
  • 4
    I really don't understand why the control would behave differently to the browser - seems completely unintuitive :( I'm thinking of just sending WebRequests myself and parsing the results into my own UI. I was trying to avoid it, but it's probably going to be the easiest solution! – Danny Tuppeny Jul 16 '11 at 13:15
  • The control behaves differently than the browser because if it didn't, the user upgrading their browser could break other applications. So instead, applications must opt-in to later behaviors. – EricLaw Jul 16 '11 at 14:57
  • 1
    I'm pretty sure FEATURE_NATIVE_DOCUMENT_MODE isn't supported beyond one of the first IE8 betas and wasn't supported in the final version of IE8 either. FEATURE_BROWSER_EMULATION is what you want to use. – EricLaw Jul 16 '11 at 14:59
  • @eric - good catch...serves me right for copy and pasting instead of dumping from my own registry – Kev Jul 16 '11 at 15:00
  • @eric - ah! you're *that* "Eric Law" :). Please feel free to put me straight if there's anything else suspect about that answer. – Kev Jul 16 '11 at 15:05
  • I've decided to try and find another solution (maybe Awesomium). I don't want my app messing around in the registry for such a trivial standalone app :-( – Danny Tuppeny Jul 18 '11 at 06:08
  • @danny - It's only about two lines of code to add that setting. Anyway, considering that it's the correct answer, even if it's not the one you want to hear, do I get a tick/+1 :) – Kev Jul 18 '11 at 08:55
  • @Kev - Sorry, thought I'd already marked it! It's not about the code, it's about modifying the registry - I'd like the app to require as few permissions as possible (it may end up being ClickOnce) and do as little as possible to my users machines :( – Danny Tuppeny Jul 18 '11 at 09:52
  • @danny - I understand. As you probably noticed, Eric Law chipped on the comments above - who is the author of Fiddler and is "dah man" when it comes to IE. I'm sure he'd have had something to say if there was a more elegant way around this. Not sure if it helps, but there's also a webkit control for .NET, never tried it, but might be worth a look: http://sourceforge.net/projects/webkitdotnet/ – Kev Jul 18 '11 at 10:09
  • Interesting - might have a look. I was trying to use Awesomium, but it caused VS to crash enough times that I got angry and abandoned it! ;( – Danny Tuppeny Jul 18 '11 at 10:54
  • Great answer! Really helpfull! Just add DWORD with the same value as sllauncher.exe has, and that is it! – Mike Keskinov Aug 10 '12 at 16:54
  • 1
    Also, use value `10001` for IE10. – Chris O Jul 19 '13 at 20:27
  • And the value for IE11? from where did you get this one @ChrisO? – Jack Jul 12 '14 at 07:39
  • 1
    The decimal value for IE11 is simply: 11000. – alex Oct 04 '15 at 12:10
  • Am I alone in noticing that it does not matter which value your dword is set to - as long as you add a reg key with the executable where the WebBrowser is invoked - this will bypass the default IE7 ? – Veverke Nov 27 '16 at 08:30
26

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

Todd Horst
  • 853
  • 10
  • 22
5

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

mbokil
  • 3,202
  • 30
  • 22
2

I know that this is an old question but there's a way to insert a header in the webbrowser control in Visual Basic 2010 and later in order to disable the compatibility view:

The first thing you need to do is to catch the current web page and then replace the head tag as follows:

Sub compatible()
' --- simple routine to disable compatible view.

    Dim the_url As String
    Dim message As String
    Dim theReplacement As String
    Dim oldMessage As String

    the_url = WebBrowser1.Url.OriginalString

    WebBrowser1.Navigate(the_url)

    message = "<head>" + Chr(13) + Chr(10) + "<meta http-equiv=" + Chr(34) + "X-UA-Compatible" + Chr(34) + "content=" + Chr(34) + "IE=edge" + Chr(34) + " />" + Chr(13) + Chr(10) + "<base href=" + Chr(34) + the_url + Chr(34) + ">"

    oldMessage = WebBrowser1.DocumentText.ToString()

    theReplacement = Replace(oldMessage, "<head>", message)
    WebBrowser1.DocumentText = theReplacement

End Sub

This code adds the two following lines in the webbrowser control:

<meta http-equiv="X-UA-Compatible"content="IE=edge" />
<base href="(url of the web page)">
  • 1
    This should work; though it's possible a bit risky (could results in duplicate requests going to the server for ajax, etc.). You'd probably need to test it really well against the specific site(s) you expect to have in the control. – Danny Tuppeny Jul 10 '13 at 12:20