views:

182

answers:

3

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>");
+1  A: 

You can also use WebBrowser.DocumentStream Property to write the data you need.

Giorgi
A: 

You can use IHtmlDocument.

Beatles1692
A: 

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.

Senseful