.Net WebBrowser.DocumentText Isn't Changing!

后端 未结 9 2100
不思量自难忘°
不思量自难忘° 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:58

    Make sure that you do not cancel Navigating event of WebBrowser for about:blank page. WebBrowser navigates to about:blank before setting DocumentText. So if you want to handle links by yourself you need to create following handler of Navigating event:

    private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
    {
        if(e.Url.OriginalString.StartsWith("about:"))
        {
            return;
        }
        e.Cancel = true;
        // ...
    }
    

提交回复
热议问题