Reputation: 3379
I have a very simple forms application with WebBrowser control on the form which I want to use to debug rendering issues, especially which documentType is used by the browser.
When I navigate in IE to the website, it's easy - I open up the JS console and type document.documentType
and get value.
How can I achieve the same from the C# and WebBrowser
control?
I have tried:
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
if (webBrowser1.Document != null)
{
var document = webBrowser1.Document;
mshtml.IHTMLDocument doc = (mshtml.IHTMLDocument) document.DomDocument;
}
}
But the doc
doesn't seem to surface documentMode
property easily.
Upvotes: 0
Views: 412
Reputation: 125247
You can cast the Document.DomDocument
to dynamic
and get the document mode using documentMode
property:
var documentMode = ((dynamic)(webBrowser1.Document.DomDocument)).documentMode;
Just make sure you are using the code in DocumentCompleted
event of WebBrowser
.
Upvotes: 1