What's the proper way to write HTML to a WebBrowser in C#?

browser, c#, html

Solution

Using this (instead of the about:blank document.write combo):

myWebBrowser.DocumentText = sourceCode;

seems to solve various issues such as running the following JavaScript when IE7 is installed on the system:

window.location = "#test";

If IE 7 is installed, this will cause an Error: Invalid argument message to appear.

Problem

If instead of navigating to a webpage in a WebBrowser, you want to set the HTML property directly, what's the proper way to do it? Is it like this? ``` myWebBrowser.Navigate("about:blank"); myWebBrowser.Document.Write("<html><body>Test</body></html>"); ```

Original source