Share via

NavigateError Event

Fires when an error occurs during navigation.


  Private Sub object_NavigateError( _
  ByVal pDisp As Object, _
  ByVal URL As Variant, _
  ByVal TargetFrameName As Variant, _
  ByVal StatusCode 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 failed navigation.

  • URL
    String expression that evaluates to the URL for which navigation failed.

  • TargetFrameName
    String that evaluates to the name of the frame in which the resource is to be displayed, or Null if no named frame is targeted for the resource.

  • StatusCode
    Integer that contains a status code corresponding to the error, if available. For a list of the possible status codes, see NavigateError Event Status Codes.

  • Cancel
    Boolean that specifies whether to cancel the navigation to an error page and/or any further autosearch.

    • False
      Default. Continue with navigation to an error page or autosearch.
    • True
      Cancel navigation to an error page or autosearch.


NavigateError was introduced in Microsoft Internet Explorer 6.

This event fires before Windows Internet Explorer displays an error page due to an error in navigation. An application has a chance to stop the display of the error page by setting the Cancel parameter to True. However, if the server contacted in the original navigation supplies its own substitute page navigation, when you set Cancel to True, it has no effect, and the navigation to the server's alternate page proceeds. For example, assume that a navigation to causes this event to fire because the page does not exist. However, the server is set to redirect the navigation to In this case, when you set Cancel to True, it has no effect, and navigation proceeds to

Use the pDisp parameter to match this event with its corresponding Navigate event or Navigate2 event. For example, multiple NavigateError events can fire for a single Navigate request or Navigate2 request. Reasons for this include navigation to a URL with multiple frames, or multiple attempts by an autosearch engine to resolve an invalid URL. In each of these cases, the URL passed into these events might not match the URL that was originally requested. However, each of these events has the same pDisp.

As with other events, you can trap the NavigateError event by implementing IDispatch::Invoke as your event sink, and connecting it to the WebBrowser control's DIID_DWebBrowserEvents2 connection point. You can then extract information, such as the status code, from the pDispParams parameter. The following shows how to trap the NavigateError event and extract the status code and IDispatch pointer.

HRESULT CAtlWbHost::Invoke(DISPID dispIdMember,
                           REFIID riid,
                           LCID lcid,
                           WORD wFlags,
                           DISPPARAMS *pDispParams,
                           VARIANT *pvarResult,
                           EXCEPINFO *pexcepinfo,
                           UINT *puArgErr)
        //Extract the status code from the DISPPARAMS structure
        VARIANT * vt_statuscode = pDispParams->rgvarg[1].pvarVal;
        DWORD  dwStatusCode =  vt_statuscode->lVal;
        //Extract the event's IDispatch pointer
        IDispatch *pdispFiredEvent = pDispParams->rgvarg[4].pdispVal;

A URL passed into Navigate or Navigate2 might not match the URL passed into this event because the URL goes through a normalization process. For example, the URL string "" might be passed into Navigate2, but because of the normalization process, the URL parameter is set to ""

Applies To

WebBrowser, InternetExplorer