Share via

BeforeNavigate2 Event

Fires before navigation occurs in the given object (on either a window element or a frameset element).


  Private Sub object_BeforeNavigate2( _
  ByVal pDisp As Object, _
  ByRef Url As Variant, _
  ByRef Flags As Variant, _
  ByRef TargetFrameName As Variant, _
  ByRef PostData As Variant, _
  ByRef Headers As Variant, _
  ByRef Cancel As Boolean)


  • object
    Object expression that resolves to the objects in the Applies To list.
  • pDisp
    Object that evaluates to the top-level or frame WebBrowser object corresponding to the navigation.

  • Url
    String expression that evaluates to the URL to which the browser is navigating.

  • Flags
    Integer expression that contains the following flag, or zero.

    • &H0001
      Windows Internet Explorer 7 or later. This navigation is the result of an external window or tab that targets this browser.
  • TargetFrameName
    String expression that evaluates to the name of the frame in which the resource will be displayed, or Null if no named frame is targeted for the resource.

  • PostData
    Data to send to the server if the HTTP POST transaction is being used.

  • Headers
    Value that specifies the additional HTTP headers to send to the server (HTTP URLs only). The headers can specify such things as the action required of the server, the type of data being passed to the server, or a status code.

  • Cancel
    Boolean value that the container can set to True to cancel the navigation operation, or to False to allow it to proceed.


The BeforeNavigate2 event replaces the BeforeNavigate and FrameBeforeNavigate events, which should no longer be used. The pDisp parameter that specifies the corresponding WebBrowser object identifies where the navigation is to occur. Microsoft Internet Explorer 3.0 required the FrameBeforeNavigate and a target frame name to identify the target of navigation. However, this solution was ambiguous, because frame names are not unique.

Note  Internet Explorer 4.0 and later continue to fire the BeforeNavigate and FrameBeforeNavigate events for compatibility with Internet Explorer 3.0.

The pDisp parameter specifies the WebBrowser object of the top-level frame that corresponds to the navigation. Navigation to a different URL might occur as a result of external automation, internal automation from a script, or the user clicking a link or typing in the address bar. The processing of this navigation can be modified by setting the Cancel parameter to True, and ignoring or resending a modified navigation method to the WebBrowser object.

When you resend a navigation for the WebBrowser object, the Stop method must first be executed for pDisp. This prevents a web page that declares a canceled navigation from appearing while the new navigation is being processed.

Applies To

InternetExplorer, WebBrowser

See Also

NavigateComplete2, Navigate2, Navigate