Twebbrowser:determine when a page with Frames is completed

Source: Internet
Author: User

Twebbrowser:determine when a page with Frames is completed

6 comments. Current Rating: (3 votes). Leave comments and/or rate it.

Question:

If I Load a Web page with Twebbrowser This contains frames then theOnDocumentComplete () is hits for each frame. How can I recognize the page are completely loaded (no more frames missing)?

Answer:

Indeed, in case of multiple frames, OnDocumentComplete gets fired multiple times. Not every frame fires this event, but each frame that fires a Downloadbegin event would fire a corresponding documentcomple Te event.

How can the ' real completion ' be recognized?

The OnDocumentComplete event sends parameter Pdisp:idispatch, which is the IDispatch of the frame (SHDOCVW) for which DocumentComplete is fired. The top-level frame fires the documentcomplete in the end.

So, to-check if a page is do downloading, need to check if pdisp is same as the IDispatch of the WebBrowser cont Rol.

That's what the code below demonstrates.

  procedure  tform1.webbrowser1documentcomplete (Sender:               TObject;  Const  Pdisp:idispatch;  var  Url:olevariant);   var   Curwebrowser:iwebbrowser;  Topwebbrowser:iwebbrowser;  Document:olevariant; windowname:string;  Begin    {tform1.webbrowser1documentcomplete} curwebrowser: = Pdisp as Iwebbrowser; Topwebbrowser: = (Sender as Twebbrowser).   Defaultinterface;  If  Curwebrowser=topwebbrowser  then   begin  ShowMessage ( "   Document is complete. ' ]   End     Else       Begin      Document: = curwebrowser.document;     Windowname: = Document.ParentWindow.Name;  ShowMessage (' Frame ' + Windowname + ' is loaded. ')  end;   end;   

Twebbrowser:determine when a page with Frames is completed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.