HTML - 我怎么知道,当所有的帧都装?

问题描述:

我使用.NET WebBrowser控件。
我怎么知道当一个网页完全加载?

I'm using .NET WebBrowser control. How do I know when a web page is fully loaded?

我想知道什么时候浏览器未获取任何数据。 (当IE写入完成的那一刻在状态栏...)。

I want to know when the browser is not fetching any more data. (The moment when IE writes 'Done' in its status bar...).

注:


  • 的的DocumentComplete / NavigateComplete事件可能包含多个框架的网站多次出现。

  • 浏览器就绪状态不解决此问题有两个。

  • 我已经试过检查帧集合中的帧数再算上我得到DocumentComplete事件的次数,但是这并不能工作。

  • this.WebBrowser.IsBusy也不起作用。在文档处理程序完成检查时,它始终是'假'。

下面是最终为我工作:

       public bool WebPageLoaded
    {
        get
        {
            if (this.WebBrowser.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
                return false;

            if (this.HtmlDomDocument == null)
                return false;

            // iterate over all the Html elements. Find all frame elements and check their ready state
            foreach (IHTMLDOMNode node in this.HtmlDomDocument.all)
            {
                IHTMLFrameBase2 frame = node as IHTMLFrameBase2;
                if (frame != null)
                {
                    if (!frame.readyState.Equals("complete", StringComparison.OrdinalIgnoreCase))
                        return false;

                }
            }

            Debug.Print(this.Name + " - I think it's loaded");
            return true;
        }
    }

在我运行在所有的HTML元素,并检查所有框架中找到的每个文档完整的事件(我知道这是可以优化)。对于每一帧我检查其准备状态。
这是pretty可靠的,但就像jeffamaphone说我已经看到触发一些内部刷新网站。
但上面的code满足我的需求。

On each document complete event I run over all the html element and check all frames available (I know it can be optimized). For each frame I check its ready state. It's pretty reliable but just like jeffamaphone said I have already seen sites that triggered some internal refreshes. But the above code satisfies my needs.

编辑:每一帧都可以包含在它的帧,所以我觉得这个code应更新为递归查询每一帧的状态

every frame can contain frames within it so I think this code should be updated to recursively check the state of every frame.