views:

193

answers:

2

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.

+1  A: 

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
Thanks. I have added the X-UA-Compatible meta tag. Still trying to confirm if it does the trick...
KristoferA - Huagati.com
What was the result of using the meta tag? I was able to test it and it worked.
Garett
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 - Huagati.com
+1  A: 

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 -MSFT-
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 - Huagati.com
Unfortunately, that is not a supported scenario.
EricLaw -MSFT-
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 - Huagati.com
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 -MSFT-
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 - Huagati.com
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
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 -MSFT-