Embedded WebBrowser in a Windows Form C # project

I have a form with a built-in web browser. I currently use WebBrowserand use it like this:

webBrowser1.Navigate("about:blank");
HtmlDocument doc = this.webBrowser1.Document;
doc.Write(string.Empty);
String htmlContent = GetHTML();
doc.Write(htmlContent);

This correctly writes the HTML to the web browser control, but it never clears the existing data, but simply adds it, so I end up with N web pages stacked on top of each other.

Is this the best control? If so, why does this not clear existing data?

+3
source share
3 answers

You need to use:

HtmlDocument doc = this.webBrowser1.Document.OpenNew(true);

Now the contents of the document will be cleared before recording.

Write OpenNew, . Write HTML- . , HtmlElement InnerHtml.

+3

HtmlDocument.OpenNew :

OpenNew , , . WebBrowser .

0

All Articles