.Net WebBrowser.DocumentText Isn't Changing!

后端 未结 9 2097
不思量自难忘°
不思量自难忘° 2020-12-09 01:14

In my vb.net program, I am using a webbrowser to show the user an HTML preview. I was previously hitting a server to grab the HTML, then returning on an asynchronous thread

相关标签:
9条回答
  • 2020-12-09 01:31

    That worked for me:

    webBrowser.Navigate("about:blank");
    webBrowser.Document?.Write(htmlString);
    
    0 讨论(0)
  • 2020-12-09 01:37

    I found the following and it worked!

        webBrowser.Navigate("about:blank");
        webBrowser.Document.OpenNew(false);
        webBrowser.Document.Write(html);
        webBrowser.Refresh();
    
    0 讨论(0)
  • 2020-12-09 01:44

    please refer to this answer c# filenotfoundexception on webbrowser?

    0 讨论(0)
  • 2020-12-09 01:45

    Just spotted this in some of our old code.

    _webBrowser.DocumentText = builder.WriteToString( ... );
    
    Application.DoEvents();
    

    Apparently a DoEvents also kicks the browser into rendering

    0 讨论(0)
  • 2020-12-09 01:49

    While Application.DoEvents() fix it in a WinForms project, it was irrelevant in a WPF project.

    I finally got it to work by using webBrowser.Write( htmlContent ) (instead of webBrowser.DocumentText = htmlContent).

    0 讨论(0)
  • 2020-12-09 01:49

    This always works

    using mshtml;
    
    
    private IHTMLDocument2 Document
    {
        get
        {
            if (Browser.Document != null)
            {
                return Browser.Document.DomDocument as IHTMLDocument2;
            }
    
            return null;
        }
    }
    
    
    if (Document == null)
    {
        Browser.DocumentText = Contents;
    }
    else
    {
        Document.body.innerHTML = Contents;
    }
    
    0 讨论(0)
提交回复
热议问题