i am using automation (i.e. COM automation) to display some HTML in Internet Explorer (9):
ie = CoInternetExplorer.Create; ie.Navigate2("about:blank"); webDocument = ie.Document; webDocument.Write(szSourceHTML); webDocument.Close(); ie.Visible = True;
Internet Explorer appears, showing my html, which starts off as:
<!DOCTYPE html> <HTML> <HEAD> ...
Note: the html5 standards-mode opt-in doctype
html
Except that the document is not in ie9 standards mode; it's in ie8 standards mode:
If i save the html to my computer first:
and then view that html document, IE is put into standards mode:
My question is how update my SpawnIEWithSource(String html)
function to throw the browser into standards mode?
void SpawnIEWithSource(String html) { Variant ie = CoInternetExplorer.Create(); ie.Navigate2("about:blank"); webDocument = ie.Document; webDocument.Write(html); webDocument.Close(); ie.Visible = true; }
Edit: A more verbose, less understandable or readable code sample, that doesn't help further the question might be:
IWebBrowser2 ie; CoCreateInstance(CLASS_InternetExplorer, null, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_WebBrowser2, ie); ie.AddRef(); ie.Navigate2("about:blank"); IHtmlDocument doc; dispDoc = ie.Document; dispDoc.AddRef(); dispDoc.QueryInterface(IHTMLDocument2, doc); dispDoc.Release() doc.Write(html); doc.Close(); doc.Release(); ie.Visible = true; ie.Release();
Commenter asked on the ieblog entry Testing sites with Browser Mode vs. Doc Mode:
Can we get a description of how the document mode is determined when the HTML content is within an embedded webcontrol? Seems to be that the document mode is choosen differently - maybe for compatibility reasons?
MarkSil [MSFT] responded:
@Thomas: Thanks for raising that question. The WebBrowser Control determines the doc mode the same way that IE does because it contains the same web platform (e.g. there is one shared mshtml.dll across IE and WebBrowser Control hosts). The WebBrowser Control does default to the Compatibility View browser mode, which means that the default doc mode is IE7. Here is a blog post with more detail on this: blogs.msdn.com/.../more-ie8-extensibility-improvements.aspx.
To which Thomas responded:
@MarcSil (re: WebBrowser Control)
The problem with using registry entries to select document mode for WebControl is that it applies to the application as a whole. I write plugins for Google SketchUp where you have WebDialog windows to create UIs - it's just a WebBrowser control in a window. But that leads to problems as I want to force a document mode for my instance of the WebBrowser control, not for all of SU's WebBrowser controls as a whole.
So, my question is: how do you control the document mode per instance for a WebBrowser control?
Have you tried setting in your html the
<meta http-equiv="X-UA-Compatible" content="IE=9" />
or
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
which means latest version
The IE9 "version" of the WebBrowser control, like the IE8 version, is actually several browsers in one. Unlike the IE8 version, you do have a little more control over the rendering mode inside the page by changing the doctype. Of course, to change the browser mode you have to set your registry like the earlier answer. Here is the location of FEATURE_BROWSER_EMULATION:
HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER) SOFTWARE Microsoft Internet Explorer Main FeatureControl FEATURE_BROWSER_EMULATION contoso.exe = (DWORD) 000090000
Here is the complete set of codes:
The full docs:
http://msdn.microsoft.com/en-us/library/ee330730%28VS.85%29.aspx#browser_emulation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With