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 the hit 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 FR Ame (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 control.
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; |
|
|
|
|
You don ' t like the formatting? Check out Sourcecoder then!
Twebbrowser:determine when a page with Frames is completed