Mirror

How to know if loading is completed when a document contains an iFrame (Views: 101)


Problem/Question/Abstract:

If I open a document using .Navigate(URL) this document is loaded. Now, OnDocumentComplete would normally tell me when its done loading, however this document contains an iframe, and in that case the OnDocumentComplete is already fired when the first document is complete.

Answer:

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
    ShowMessage('Complete document was loaded')
  else
  begin
    Document := CurWebrowser.Document;
    WindowName := Document.ParentWindow.Name;
    ShowMessage(Format('Frame "%s" was loaded', [WindowName]));
  end;
end;

<< Back to main page