Windows 窗体 C# 项目中的嵌入式 Web 浏览器
我有一个带有嵌入式 Web 浏览器控件的表单。我目前正在使用 WebBrowser
并像这样使用它:
webBrowser1.Navigate("about:blank");
HtmlDocument doc = this.webBrowser1.Document;
doc.Write(string.Empty);
String htmlContent = GetHTML();
doc.Write(htmlContent);
这会将 HTML 正确写入 Web 浏览器控件,但它永远不会清除现有数据,它只是附加,所以我最终会得到 N 个网页堆叠在彼此之上。
这是最好的控件吗?如果是这样,为什么不清除现有数据?
I have a form with an embedded web browser control on it. I am currently using WebBrowser
and use it like so:
webBrowser1.Navigate("about:blank");
HtmlDocument doc = this.webBrowser1.Document;
doc.Write(string.Empty);
String htmlContent = GetHTML();
doc.Write(htmlContent);
This writes the HTML correctly to the web browser control BUT it never clears the existing data and it just appends, so I end up with N web pages stacked on top of each other.
Is this the best control to use? If so why is it not clearing existing data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你需要使用:
现在在写入之前会清除文档的内容。
You need to use:
now the contents of the document will be cleared before writing.
是的。
如果需要清除内容,您应该能够调用 Clear 方法。
查看本文以获取深入的详细信息和示例代码:
http://www.codeproject.com/KB/miscctrl/simplebrowserformfc.aspx
Yes, it is.
You should be able to call the Clear method if you need to clear contents.
Check this article for in-depth details and sample code:
http://www.codeproject.com/KB/miscctrl/simplebrowserformfc.aspx
在页面之间调用 HtmlDocument.OpenNew:
Call HtmlDocument.OpenNew between pages: