码迷,mamicode.com
首页 > Web开发 > 详细

TWebBrowser: Determine when a page with Frames is completed

时间:2014-12-24 13:06:55      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

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 { 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

标签:

原文地址:http://www.cnblogs.com/honeynm/p/4182020.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!