1 out of 1 rated this helpful - Rate this topic

DWebBrowserEvents2::NavigateError Event

Fires when an error occurs during navigation.

Syntax


void NavigateError(
    IDispatch *pDisp,
    VARIANT *URL,
    VARIANT *TargetFrameName,
    VARIANT *StatusCode,
    VARIANT_BOOL *Cancel
);

Parameters

pDisp
[in] A pointer to an IDispatch interface for the WebBrowser object that represents the window or frame in which the navigation error occurred. This interface can be queried for the IWebBrowser2 interface.
URL
[in] A pointer to a VARIANT structure of type VT_BSTR that contains the URL for which navigation failed.
TargetFrameName
[in] A pointer to a VARIANT structure of type VT_BSTR that contains the name of the frame in which to display the resource, or NULL if no named frame was targeted for the resource.
StatusCode
[in] A pointer to a VT_I4 containing an error status code, if available. For a list of the possible HRESULT and HTTP status codes, see NavigateError Event Status Codes.
Cancel
[in, out] A pointer to a VARIANT structure of type VARIANT_BOOL that specifies whether to cancel the navigation to an error page or to any further autosearch.
VARIANT_FALSE
Default. Continue with navigation to an error page or autosearch.
VARIANT_TRUE
Cancel navigation to an error page or autosearch.

Return Value

No return value.

Event DISPID


DISPID_NAVIGATEERROR

The DISPID for this event is defined in exdispid.h. Use this value to identify the event handler when implementing IDispatch::Invoke.

Remarks

DWebBrowserEvents2::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 VARIANT_TRUE. However, if the server contacted in the original navigation supplies its own substitute page navigation, when you set Cancel to VARIANT_TRUE, it has no effect, and the navigation to the server's alternate page proceeds. For example, assume that a navigation to http://www.www.wingtiptoys.com/BigSale.htm causes this event to fire because the page does not exist. However, the server is set to redirect the navigation to http://www.www.wingtiptoys.com/home.htm. In this case, when you set Cancel to VARIANT_TRUE, it has no effect, and navigation proceeds to http://www.www.wingtiptoys.com/home.htm.

Use the pDisp parameter to match this event with its corresponding IWebBrowser2::Navigate event or IWebBrowser2::Navigate2 event. For example, multiple DWebBrowserEvents2::NavigateError events can fire for a single IWebBrowser2::Navigate request or IWebBrowser2::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 DWebBrowserEvents2::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 DWebBrowserEvents2::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)
{
    switch(dispIdMember)
    {
    ...
    case DISPID_NAVIGATEERROR : 
        //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;
		...
        break;
    ...
}
	


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

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
how to identify certificate errors?
how to identify certificate errors?

[tfl - 25 09 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
Windows : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.windows%2C&
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&