9

I'm hosting MSIE in a winforms form. Unfortunately it insists on running in compatibility mode regardless of if I give it a page that runs in IE8 mode in stand-alone IE. The effect of that is that some content that renders correctly in stand-alone MSIE gets completely mis-aligned and messed up in the hosted control.

Besides document type etc, is there some magic way to tell the webbrowser that I want it to render the page the same way as if I loaded it in stand-alone MSIE?

I don't want to use the registry key override ( http://blogs.msdn.com/b/ie/archive/2009/03/10/more-ie8-extensibility-improvements.aspx ) due to my form being part of an add-in for another app. I don't want to change the IE behavior for the main app and I don't want to change it for other add-ins running under that app. I only want this to work within the browser hosted in my form, not app-wide and not process-wide.

KristoferA
  • 12,287
  • 1
  • 40
  • 62

2 Answers2

10

I have not tested this, but how about using the META tag, along with the HTTP-EQUIV attribute, to set the X-UA-COMPATIBLE value to IE=8, which instructs the web browser to display a page in IE 8 standards mode. An example would be:

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

From this line in the following article it seems that this should work.

By default, applications hosting the WebBrowser Control open standards-based pages in IE7 mode unless the page contains an appropriate X-UA-Compatible header. You can change this by adding the name of the application executable file to the FEATURE_BROWSER_EMULATION feature control key and setting the value accordingly.

Garett
  • 16,632
  • 5
  • 55
  • 63
  • Thanks. I have added the X-UA-Compatible meta tag. Still trying to confirm if it does the trick... – KristoferA Aug 26 '10 at 03:52
  • What was the result of using the meta tag? I was able to test it and it worked. – Garett Aug 30 '10 at 04:14
  • So far I have an inconclusive test result on the meta tag. Inconclusive because after applying the tag it was rendered properly, but after changing the meta tag to IE7 it still rendered correctly, and after removing it again it still rendered properly. In other words, after the first round of tests I wasn't able to reproduce the rendering bug I was seeing before using the meta tag. I need to do some more tests but haven't had time to do so yet... – KristoferA Aug 30 '10 at 13:54
  • i tried using `X-UA-Compatible` also (http://stackoverflow.com/questions/4097593/how-to-put-the-webbrowser-control-into-ie9-into-standards). It didn't work for me either. – Ian Boyd Mar 02 '11 at 12:38
  • 5
    @Ian Boyd - make sure the X-UA-Compatible thingie is the _first_ tag inside the tag... if not, IE ignores it. – KristoferA Mar 02 '11 at 12:49
  • That's a good note, Kristofer. From http://msdn.microsoft.com/en-us/library/cc288325(v=vs.85).aspx ("The X-UA-Compatible header is not case sensitive; however, it must appear in the header of the webpage (the HEAD section) before all other elements except for the title element and other **meta** elements.") – Ian Boyd Mar 21 '11 at 14:49
3

To change the default behavior of the Web Browser Control running in your application to match what IE itself does, you must set the FEATURE_BROWSER_EMULATION Feature Control Key.

For instance, you can mimic IE8's behavior (allowing sites to render in IE8 standards mode) as follows.

Inside HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl

Create a new key named FEATURE_BROWSER_EMULATION

Inside that key, add a new REG_DWORD with value 8000 with the name of your application's executable. E.g.:

"YourApp.exe" = dword 8000 (Hex: 0x1F40)

Further details are at: http://blogs.msdn.com/b/ie/archive/2009/03/10/more-ie8-extensibility-improvements.aspx

EricLaw
  • 56,563
  • 7
  • 151
  • 196
  • The problem is that my app is actually an add-in that is running inside another app. The main app hosts MSIE as well, and so does other add-ins for it. By adding feature control registry key I will change the behavior application wide and introduce unwanted behavior/rendering. I want to change it for only the one form where I host MSIE while leaving all other browsers running under the same main executable intact. – KristoferA Aug 30 '10 at 09:11
  • 2
    Unfortunately, that is not a supported scenario. – EricLaw Aug 31 '10 at 04:44
  • Ok, thanks. How about future versions of IE, will they also act as if they were an earlier version when hosted in another process? I must say I find it strange that IE8 doesn't behave like IE8 by default, and then use the registry thingie for those who want it to behave like IE7/6/5/etc – KristoferA Aug 31 '10 at 05:08
  • 1
    IE9 behaves as IE8 does and requires opt-in. The point here is that emulating legacy versions when hosted is that it allows users to fearlessly install new versions of IE without it breaking their other applications. – EricLaw Aug 31 '10 at 21:25
  • Oh well, it breaks those apps that _want_ it to use standards mode. :) Maybe some future version could have a magic way (besides registry keys and http headers) that tell it to use standards mode rendering? Semi-related: a 'about:blank' alternative that is rendered in standards mode rather than quirks would also be neat. – KristoferA Sep 01 '10 at 01:11
  • 1
    It would have been nice if they updated the `CoInternetSetFeatureEnabled` API to add this feature, which would allow us to avoid the registry altogether, but I noticed `urlmon.h` did not contain this enumeration. Wishfull thinking I guess. – Garett Sep 01 '10 at 04:15
  • Enabling for CoInternetSetFeatureEnabled would have been nice, although I still don't think that would have met the OP's needs as he wants multiple OCs in the same process with different opt-in settings. – EricLaw Sep 01 '10 at 13:42
  • @EricLaw -MSFT Is there *any* way my hosted browser can display standards html ? – Ian Boyd Mar 02 '11 at 12:41