【问题标题】:"System.Windows.Forms.HtmlDocument" message appears when navigate webbrowser浏览网络浏览器时出现“System.Windows.Forms.HtmlDocument”消息
【发布时间】:2011-02-06 15:51:10
【问题描述】:

当我尝试将存储在字符串中的特定 html 数据设置到 webbrowser 中时,会出现此消息而不是 html 内容

System.Windows.Forms.HtmlDocument

我的代码是:注意 html 代码存储在 temp_data 中

this.main_webpage.Navigate("about:blank");
HtmlDocument d_c = main_webpage.Document;
d_c.Write(temp_data);

main_webpage.DocumentText = d_c.ToString();
main_webpage.Refresh();

【问题讨论】:

    标签: c# navigation browser


    【解决方案1】:

    ToString 是继承自Object 的那个,它返回对象的类型。 HtmlDocument 不会覆盖它。

    使用HtmlDocument 的Body 属性 - 它返回正文元素:

    main_webpage.DocumentText = d_c.Body.InnerHtml;
    

    【讨论】:

    • 好,但是你的方式删除所有css代码并更改原始html代码的问题..我不明白为什么?
    • Body 属性表示文档body 标记。这将不包括header(将链接的 CSS 文件)中的任何内容。此外,HtmlDocument 解析 HTML 并创建内部表示 - 这就是您所看到的。
    猜你喜欢
    • 2013-09-20
    • 2012-10-30
    • 1970-01-01
    • 2013-03-19
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 2011-06-02
    • 2010-11-22
    相关资源
    最近更新 更多