Reputation: 12678
I use the DocumentCompleted but this gets fired multiple times. Now I've seen this example if (e.Url.AbsolutePath != this.webBrowser.Url.AbsolutePath)
which is used to confirm that the requested file is completed loading but this gets fired before anything else (like images) on the page is loaded. Thus I'm still not able to tell when a webpage is fully loaded.
Is there a way to ensure that the webpage has fully loaded and there's nothing being loaded?
Upvotes: 3
Views: 1810
Reputation: 16708
DocumentCompleted
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. You could look at the WebBrowserDocumentCompletedEventArgs
in DocumentCompleted
and check the Url property and compare that to the Url of the main page.
The easy way is to check the URL that completed loading:
void webBrowser1_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
if (e.Url.Equals(webBrowser1.Url)) {
// Here the page is fully loaded
}
}
Upvotes: 2