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

  TIEWebBrowserBeforeNavigate2 = procedure(Sender: TObject; const URL: Stringconst Browser: IWebBrowser2;  
    const pDisp: IDispatch; var NewURL: OleVariant; var Flags: OleVariant;  
    var TargetFrameName: OleVariant; var PostData: OleVariant;  
    var Headers: OleVariant; var Cancel: WordBool) of object;  
property OnWBBeforeNavigate2: TIEWebBrowserBeforeNavigate2;  

The OnWBBeforeNavigate2 event occurs immediately before some instance of Internet Explorer navigates to a new resource.  
Write an OnWBBeforeNavigate2 event handler to redirect or cancel a change to a different URL. This event may occur as the result of a call to the Navigate or Navigate2 method of Browser control, or the user clicking a link.  
The URL parameter is the current location shown in the address line of browser window.  
Browser is the pointer to IWebBrowser2 control which performs the current operation (you can use its properties and methods inside the event handler).  
pDisp is the Automation interface of the Web browser control specified by Browser.  
NewURL is the Uniform Resource Locator of the resource the Web browser is looking up. Change this value to redirect the navigation operation to a different resource.  
Flags is not currently used.  
TargetFrameName is the name of the frame in which the resource will be displayed, or NULL if the resource should not be displayed in a named frame. Change this value to change where the resource is displayed. See the Navigate method for a list of possible values.  
PostData contains the data sent to the server when the underlying operation is an HTTP post message. The event handler can change this value before it is sent to the target URL.  
Headers contains any headers sent to the servers when the URL represents an HTTP message. HTTP headers specify such things as the intended action required of the server, the type of data, and so on. (See TWebRequest object, whose properties represent many of the more common headers). The event handler can change this value before it is sent to the target URL.  
Cancel determines whether the Web browser looks up the specified resource after the event handler exits. Change Cancel to True to cancel the navigation operation.  

// tip demonstrates how to redirect navigation to another URL  
procedure TBandForm.acIESniffer1WBBeforeNavigate2(Sender: TObject;  
  const URL: Stringconst Browser: IWebBrowser2; const pDisp: IDispatch;  
  var NewURL, Flags, TargetFrameName, PostData, Headers: OleVariant;  
  var Cancel: WordBool);  
  if Pos('porn', LowerCase(NewURL)) <> 0 then  
    Cancel := True;  
    Browser.Navigate('', Flags, TargetFrameName, PostData, Headers);  

See also
OnWBNavigateComplete2 event.