webBrowser.Document.Write() Irregular Performance

感情迁移 提交于 2019-12-20 06:16:57

问题


I am using a webBrowser control as the main output window for my application. The first time I use document.write(), the text is completely replaced. The second time the text that I am writing is appended to the end. I have confirmed that I am not writing twice or adding strings too many times by accident. Why would the control behave this way?


回答1:


Call OpenNew before writing the document.

HtmlDocument doc = webBrowser1.Document.OpenNew(true);
doc.Write("<HTML><BODY>This is a new HTML document.</BODY></HTML>");



回答2:


If that doesn't work for you here is another alternative,

webBrowser1.DocumentText = "<HTML><BODY>I am Vinod Srivastav</BODY></HTML>";

which sets the HTML contents of the page displayed in the WebBrowser control.



来源:https://stackoverflow.com/questions/8591918/webbrowser-document-write-irregular-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!