zoukankan      html  css  js  c++  java
  • TWebBrowser: Determine when a page with Frames is completed

    TWebBrowser: Determine when a page with Frames is completed

    comments6 comments. Current rating: 5 stars (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;
    
     
     

    You don't like the formatting? Check out SourceCoder then!

  • 相关阅读:
    ThinPHP v5.x安装初始化配置(项目实战)
    Bresenham快速画直线算法
    arm笔记之MOV
    Blackfin DSP的C语言优化之Circular Buffer
    Visual DSP定点数(fract)使用指南
    全局二值化
    Blackfin DSP学习心得与参考资料
    Linux网络配置
    一般方程与参数方程求直线交点
    一个改进的快速排序实现
  • 原文地址:https://www.cnblogs.com/honeynm/p/4437851.html
Copyright © 2011-2022 走看看