iesniffer OnWBDownloadComplete event
Return to Introduction  Previous page  Next page
Applies to
IESniffer component.  

Declaration
type  
  TIESnifferEvent = procedure(Sender: TObject; const URL: Stringconst Browser: IWebBrowser2) of object;  
 
property OnWBDownloadComplete: TIESnifferEvent;  

Description
The OnWBDownloadComplete event occurs when a navigation operation finishes, is halted, or fails.  
 
Write an OnWBDownloadComplete event handler to take specific action after the Web browser stops a downloading operation. For example, use the OnWBDownloadComplete event to stop an download indication that is started in an OnWBDownloadBegin event handler.  
 
tip You can use this event to read or modify the content of downloaded Web page, or just highlight some keywords on the page.  
 
Note
Unlike the OnWBNavigateComplete2 event, OnWBDownloadComplete occurs even if the Web browser does not successfully navigate to an URL.  

Example 1 (demonstrates how to read all content of downloaded HTML page)
uses MSHTML; // introduces IHTMLDocument2 interface  
 
procedure TForm1.IESniffer1WBDownloadComplete(Sender: TObject;  
  const URL: Stringconst Browser: IWebBrowser2);  
var  
  doc: IHTMLDocument2;  
  Collection: IHTMLElementCollection;  
  Element: IHTMLElement;  
  HTMLPage: String;  
  PlainText: String;  
begin  
  try  
    doc := (Browser.Document as IHTMLDocument2);  
    Collection := doc.all;  
    Collection := Collection.Tags('BODY'as IHTMLElementCollection;  
    Element := Collection.Item(NULL, 0as IHTMLElement;  
 
    HTMLPage := Element.OuterHTML; // read the HTML page  
    PlainText := Element.OuterText; // or just plain text  
  except  
  end;  
end;  

Example 2 (demonstrates how to highlight some text keywords in the downloaded page)
(tip Alternatively you can use MarkText or ReplaceText methods!)  
uses MSHTML; // introduces IHTMLDocument2 interface  
 
procedure TForm1.IESniffer1WBDownloadComplete(Sender: TObject;  
  const URL: Stringconst Browser: IWebBrowser2);  
var  
  Doc: IHTMLDocument2;  
  BodyElement: IHTMLBodyElement;  
  TextRange: IHTMLTxtRange;  
  SearchFlag: Integer;  
begin  
  try  
    // http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/findtext.asp  
    SearchFlag := 2 + 4// 2 = Whole words only, 4 = Match case  
 
    Doc := Browser.Document as IHTMLDocument2;  
    BodyElement := Doc.body as IHTMLBodyElement;  
    TextRange := BodyElement.CreateTextRange;  
    try  
      while TextRange.findText('Delphi', MaxInt, SearchFlag) do  
       TextRange.pasteHTML('Delphi Rules!');  
    finally  
      TextRange._Release;  
    end;  
  except  
  end;  
end;  

See also
OnWBDocumentComplete, OnWBDownloadBegin and OnWBNavigateComplete2 events;  
MarkText and ReplaceText methods.  
File not found.