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

Declaration
type  
  TacIEWebBrowserBeforeNavigate2 = 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: TacIEWebBrowserBeforeNavigate2;  

Description
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 of IWebBrowser2 interface 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. The PostData can be extracted to normal string using following code:  
function PostDataToStr(PostData: WideString): String;  
begin  
  SetLength(Result, Length(PostData) shl 1 - 1); // -1 tailing #0  
  Move(PostData[1], Result[1], Length(Result));  
end;  
 
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.  

Example
// 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);  
begin  
  if Pos('porn', LowerCase(NewURL)) <> 0 then  
   begin  
    Cancel := True;  
    Browser.Navigate('http://www.disney.com', Flags, TargetFrameName, PostData, Headers);  
   end;  
end;  

See also
OnWBNavigateComplete2 event.