Detecting when the webpage is fully loaded with webbrowser control c#

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 00:23:23

问题


I'm using a WebBrowser control , there is an event which is called DocumentCompleted , this event is fired for each frame in the web page and also for all the child documents (e.g. JS and CSS) that are loaded.

my question is how to detect the last entry of this event, I mean how to detect when the page is fully loaded , and this event is not firing again .

I looked for this a lot , I found a solution like this :

void webBrowser1_DocumentCompleted(object sender,
        WebBrowserDocumentCompletedEventArgs e)
{
    if (e.Url.Equals(webBrowser1.Url)) {
        // Here the page is fully loaded        
    }
}

but this is not working with all the urls !

Anybody has an idea how to achieve that ?

thanx in advance


回答1:


The DocumentComplete event may be fired multiple times for a document with frames. At the same time, for a particular document, the HTML DOM window.onload event will be fired only once. Here is how to use this fact to handle the completion of the top page loading.

OTOH, some pages are quite complex and use continuous AJAX updates. Strictly speaking, it may not always be possible to determine when a page like that has finished its rendering, with 100% probability. However, you can get close, here is how.



来源:https://stackoverflow.com/questions/21708890/detecting-when-the-webpage-is-fully-loaded-with-webbrowser-control-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!