当检测网页满载WebBrowser控件C# [英] Detecting when the webpage is fully loaded with webbrowser control c#

查看:135
本文介绍了当检测网页满载WebBrowser控件C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 web浏览器控制,有被称为 DocumentCompleted 一个事件,这个事件被触发用于在网页中,也为已加载的所有子文件(如JS和CSS)每个帧。

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 ?

感谢名单提前

推荐答案

的DocumentComplete 事件可能与框架的文档被解雇多次。同时,对于一个特定的文件,HTML DOM 的window.onload 事件将被一次发射。 这里是如何利用这一点来处理页面顶部装载完毕。

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,有些页面是相当复杂的,使用连续AJAX更新。严格来说,它可能不总是可能的,以确定何时这样的页面已经完成它的渲染,以100%的概率。然而,你可以亲近,这里是怎么

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.

这篇关于当检测网页满载WebBrowser控件C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆