How to know that WebBrowser control has finished l

2019-07-27 11:14发布

问题:

is there a way to know that the WebBrowser control has finished loading the page?
currently i am using WebBrowser.ReadyState == WebBrowserReadyState.Complete.
but this indicates that the webpage content is downloaded but sometimes the flash is not loaded yet.

回答1:

A Flash file loading doesn't report its progress on that back to the browser so unfortunately you can't catch that.



回答2:

well the best thing i have found is to use a timer to wait for a specifique time like 30 seconds and then the page should be loaded.
not perfect but the best i have thought of.



回答3:

If you have control over the Flash, you can put an ActionScript event that will then get passed to the browser.



回答4:

The WebBrowser control has a DocumentCompleted event which you can catch and react on. I don't know if that includes the Flash content loading - the docs aren't very clear on that....

webBrowser1.DocumentCompleted += 
     new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);

private void webBrowser1_DocumentCompleted(object sender, 
                                     WebBrowserDocumentCompletedEventArgs e)
{
   // do whatever you need to do when the document is completely loaded here
}


回答5:

You can try this way:

bool loadingPage = true;

private void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
     if (this.ReadyState != WebBrowserReadyState.Complete) return;
     if ((e.Url.AbsolutePath == "blank") || (e.Url != this.Url)) return;
     if (this.Document.Body.All.Count < 20) return;
     loadingPage = false
}

private void WaitPageLoad()
{
     //To avoid waiting forever. You can add timer here.
     while(loadingPage)
     {
     }
}