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

Declaration
type  
  TWindowLoadState = (lsExistsLoading, lsExistsCompleted, lsLoading, lsCompleted);  
 
  TIESnifferLoadEvent = procedure(Sender: TObject; const URL: Stringconst Browser: IWebBrowser2;  
    State: TWindowLoadState) of object;  
 
property OnWindowLoad: TIESnifferLoadEvent;  

Description
The OnWindowLoad event occurs when the component detects new Internet Explorer window.  
 
The URL parameter is the text sniffed from the address line, Browser is the pointer to the TWebBrowser2 interface, detected by component. You can use the properties and methods of Browser right in this event handler.  
 
The State parameter determines whether the Internet Explorer window was already exists when your application started and whether the content of the Web page are completely loaded. There is 4 possible values for this parameter:  
ValueMeaning  
lsExistsLoadingthe IE window was already running before your application started. Its content was not completely loaded (still downloading);  
lsExistsCompletedthe IE window was already running before your application started and all its content was completely loaded (so you can change);  
lsLoadingthis is new IE window detected by program. The Web page still loading;  
lsCompletedthis is new IE window, and the Web page already completed (even ready to be modified!, see OnWBDownloadComplete event for more details and sample code which shows how to dynamically modify the Web page content);  
 
tip If SniffWithHTTPPrefixOnly property is True, the component will detect only that windows which already have "http" prefix in the address line (shows content received by HTTP or HTTPS protocols). Otherwise, if SniffWithHTTPPrefixOnly is False, the component can detect windows with any text in the address line, even if it's "about:blank" or path to some local directory in Windows Explorer.  
 
iiwarning The OnWBDownloadComplete event will be triggered if the Explorer window was detected with IsCompleted status (if the window was not existeted on application startup but the content was already completed upon detecting the IE instance).  
 
iiinfo The OnURLChange event will occur at once after detecting of new IE window.  

Example (demonstrates how to replace the text if the page already completed, but you can do the same in OnWBDownloadComplete event handler)
procedure TForm1.IESniffer1WindowLoad(Sender: TObject; const URL: String;  
  const Browser: IWebBrowser2; State: TacWindowLoadState);  
const  
  StateStr: Array[TacWindowLoadState] of String = ('Exists Loading''Exists Completed',  
                                                   'New Loading''New Completed');  
begin  
  Label1.Caption := StateStr[State];  
  if (State = lsExistsCompleted) or (State = lsCompleted) then  
    IESniffer.ReplaceText(Browser, 'Delphi''Delphi Rules!');  
end;  

See also
SniffWithHTTPPrefixOnly property;  
OnWindowUnload, OnWBDownloadComplete and OnURLChange events.