Delphi .NET (2) Database (71) Delphi IDE (89) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280)
Exchange Links About this site Links to us 
|
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 that contains frames then the OnDocumentComplete() is hit for each frame. How can I recognize that the page is 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 will fire a corresponding DocumentComplete 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 done downloading, you 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
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!
Comments:
|
anonymous from Germany
|
 |
|
|
THANKS IT HELPED ME ALOT!
|
|
anonymous from Russian Federation
|
|
|
|
Great solution, but how to Fire Event For each Frame befoure it will be shown ?
It seems me that all frames are fired parralel and I cannot remove for example Exploits from there dynamicaly.
If I do it with OnNavigateComplete event it is fired after main document or Frame is loaded. But frame goes on loading when it is fired and Javascripts are runned befoure I can filter them from event.
|
|
anonymous from Russian Federation
|
|
|
|
May be there is any other simple way to Filter all incoming traffic to TWebBrowser of TEmbeddedWB and it's Frames
and remove any bad Javascripts from there ?
|
|
chperetti@infomaniak.ch from France
|
 |
|
|
Thanks you for this good code and explanations
|
|
anonymous from United States
|
 |
|
|
Excellent help!
Thanks for the tips, what would we do without the Internet!
|
|
|
|
|
ok
this is good code
but there are some problem
if ur broser don't find the page of your url it will dowload the error page defult
this code can not detect that page is error page ok
|
|