iesniffer IESniffer component
Properties Methods Events
Return to Introduction  Previous page  Next page
Overview
The IESniffer monitors all running instances of Internet Explorer (or just some certain browser window(s)), sniffs the URL address from address line and gives an access to all their properties, methods and events (without implementing/installing ANY Browser Helper Objects). The component can work either in stand-alone Delphi/BCB application or can be put to Explorer Toolbar written with Delphi/BCB. The component allows:  
·list the URLs which currently are available in the address lines of each browser window, and to be notified when the address changes;  
·detect when new Internet Explorer window appears and when user close the window;  
·hook each event of the Internet Explorer, modify its properties and call their methods, just like you are using usual TWebBrowser component;  
·retrieve and modify the content of each page (its text, tags, links, images etc), for example you may highlight some text, remove or change the text, tags etc;  
·automatically fill the Web forms (with IESnifferAutoFillUserInfo component);  
·redirect navigation to different URL when some keywords are detected in the address line;  
·automatically redirect searches from default MSN to another specified search engine (it works when user enters search terms right in address line without specifying correct address);  
·prevent popup windows to be opened, and so on…  
 
iiwarning This component available only in Delphi/BCB 5 and higher versions and works with Internet Explorer 4 and higher (unfortunately IWebBrowser2 and DWebBrowserEvents2 interfaces does not supported in earlier versions).  

How does it works?
The IE Sniffer contantly monitors the shell for new instances of Internet or Windows explorer (with the interval specified in MonitorInterval property). When it detects new instance of Explorer, it triggers OnWindowLoad event, adds the detected instance to the internal list, and starts hooking all events of that browser, by connecting to its IWebBrowser2 interface (Note: the component does NOT hooks events of Windows Explorer, you can receive events only from IE). When user close the Explorer window, it triggers OnWBQuit (window is about to be closed), then the OnWindowUnload event (window are closed and all its handles already destroyed).  

How to use?
First drop the component onto your form and specify the interval between checking for new Explorer windows to MonitorInterval property. If you just want to detect when the new URL appears in some browser window, and to be notified when the address changes — write OnURLChange event handler. To be notified when the new Explorer window opens — use OnWindowLoad event, to take some specific actions when user closes the window — write OnWindowUnload event handler, or use OnWBQuit event instead when the Internet Explorer window is only about to be closed. If you want to detect only windows with "http" prefix (with content received by HTTP or HTTPS protocols — set SniffWithHTTPrefixOnly property to True). Also you can always receive the full list of URLs which currently are available in all Explorer windows by reading the URLs property.  
 
If you don't need to hook events from ALL instances of Internet Explorer and just want to receive events from some certain browser window — set Active property to False (component will not detect IE windows automatically), and add some certain browser window for monitoring with AddBrowser method.  
 
If you want to perform some more complicated tasks (like grabbing the content of browser window, or modifying it, or something else that can be done with browser), you should access its IWebBrowser2 interface. To access it, you can use the numerous events (each event passes the pointer to IWebBrowser2 instance), or use IEList property to enumerate each instance of Internet Explorer and play with their properties and methods. If you wish to replace or highlight some text when the page is downloaded — use MarkText or ReplaceText methods in the OnWBDownloadComplete and OnWindowLoad event handlers.  
 
Here is simple example which demonstrates how to highlight some word on the downloaded HTML document:  
procedure TForm1.IESniffer1WBDownloadComplete(Sender: TObject;  
  const URL: Stringconst Browser: IWebBrowser2);  
begin  
  IESniffer1.MarkText(Browser, 'Delphi', clBlack, clYellow);  
end;  
 
To clear the marks — use ClearMarks method:  
procedure TForm1.ClearBtnClick(Sender: TObject);  
begin  
  IESniffer1.ClearMarks(Browser);  
end;  
 
If you wish to redirect the navigation to another URL when some keywords are detected in the address line you can use following example:  
procedure TBandForm.IESniffer1WBBeforeNavigate2(Sender: TObject;  
  const URL: Stringconst Browser: IWebBrowser2; const pDisp: IDispatch;  
  var NewURL, Flags, TargetFrameName, PostData, Headers: OleVariant;  
  var Cancel: WordBool);  
begin  
  if Pos('porn', LowerCase(URL)) <> 0 then  
   begin  
    Cancel := True;  
    Browser.Navigate('http://www.disney.com', Flags, TargetFrameName, PostData, Headers);  
   end;  
end;  
 
Here is another example how to block all popup windows before they will be displayed. This is VERY simple example, but it works and kills ALL popup windows (which don't have the toolbar):  
procedure TBandForm.IESniffer1WBBeforeNavigate2(Sender: TObject;  
  const URL: Stringconst Browser: IWebBrowser2; const pDisp: IDispatch;  
  var NewURL, Flags, TargetFrameName, PostData, Headers: OleVariant;  
  var Cancel: WordBool);  
begin  
  Cancel := Browser.Toolbar = 0;  
end;  
Also if your popup killer software operates with "white" and "black" lists, you can additionally check the URL parameter and if it contains some unwanted text (domain name or keyword), you can allow or disallow the navigation accordingly.  
Additionally, you can check the state of Ctrl key (like Google toolbar does) and always allow the navigation when Ctrl key pressed.  

Note for C++ Builder developers
iiwarning When you will build the project with IESniffer, you may get following compiler error:  
[C++ Error] SHDocVw.hpp(893): E2293 ) expected, at the following line:  
/* TWinControl.CreateParented */ inline __fastcall TWebBrowser(HWND ParentWindow) : Olectrls::TOleControl(ParentWindow) { }  
 
Please manually edit the SHDocVw.hpp and change this line to  
/* TWinControl.CreateParented */ inline __fastcall TWebBrowser(HANDLE ParentWindow) : Olectrls::TOleControl(ParentWindow) { }  
 
Also you can get another linker error:  
IESniffer.hpp E2209 Unable to open include file 'MSHTML.hpp'.  
Please just replace MSHTML.hpp to MSHTML.h. For some reason BCB comes with MSHTML.h file instead of *.hpp.  

Code example
In Delphi: http://www.appcontrols.com/demos/iesnifferdemo-delphi.zip  
Compiled executable: http://www.appcontrols.com/download/exe/IESnifferDemo.exe  

See also
IESnifferAutoFillUserInfo component.