简体   繁体   English

在C#中将HTML写入WebBrowser的正确方法是什么?

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

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? 如果不是导航到WebBrowser中的网页,而是想直接设置HTML属性,那么正确的方法是什么?

Is it like this? 是这样的吗?

myWebBrowser.Navigate("about:blank");
myWebBrowser.Document.Write("<html><body>Test</body></html>");

Using this (instead of the about:blank document.write combo): 使用此(而不是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: 似乎解决了各种问题,例如在系统上安装IE7时运行以下JavaScript:

window.location = "#test";

If IE 7 is installed, this will cause an Error: Invalid argument message to appear. 如果安装了IE 7,则会出现错误:无效参数消息。

您还可以使用WebBrowser.DocumentStream属性来编写所需的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM