IHTMLWindow2::get_onbeforeunloadIHTMLWindow2::get_onbeforeunload*
*Contents  *Index  *Topic Contents
*Previous Topic: IHTMLWindow2::get_offscreenBuffering
*Next Topic: IHTMLWindow2::get_onblur

IHTMLWindow2::get_onbeforeunload


HRESULT get_onbeforeunload( 
    VARIANT *p
);

Retrieves the inline script associated with the onbeforeunload event before a window element is unloaded. This event is fired before the onunload event. It provides an opportunity to warn the user if the window is currently in an unsaved state and the information will be lost.

For more information on inline script, see Attaching an Event Handler in the Event Model documentation.

p
Address of a VARIANT structure that contains the script.

The handler for this event should return NULL if doing the unload is safe, or a text string to prompt the user to decide to cancel or continue with the unload operation. Only the user's response to the warning can stop the new navigation causing the unload; the event handler itself cannot unilaterally block the operation. If the handler returns a non-NULL string, a modal dialog box appears that displays the explanatory string. The dialog box shows three buttons with the message for user action:

In the case of frames, the full sequence of onbeforeunload events are fired on each frame in the same order, depth-first, that onunload events are about to be fired. A dialog box is presented for each event handler that returns a non-NULL string. The first Cancel response stops the potential navigation, in which case no unload occurs. If there is no Cancel response, the unload proceeds and onunload events fire.

See also put_onbeforeunload

Up Top of Page


IHTMLWindow2::put_onbeforeunload


HRESULT put_onbeforeunload(
    VARIANT v 
);

Sets the inline script associated with the onbeforeunload event before a window element is unloaded. This event is fired before the onunload event. It provides an opportunity to warn the user if the window is currently in an unsaved state and the information will be lost.

For more information on inline script, see Attaching an Event Handler in the Event Model documentation.

v
VARIANT structure that contains the script to be set.

The handler for this event should return NULL if doing the unload is safe, or a text string to prompt the user to decide to cancel or continue with the unload operation. Only the user's response to the warning can stop the new navigation causing the unload; the event handler itself cannot unilaterally block the operation. If the handler returns a non-NULL string, a modal dialog box appears that displays the explanatory string. The dialog box shows three buttons with the message for user action:

In the case of frames, the full sequence of onbeforeunload events is fired on each frame in the same order, depth-first, that onunload events are about to be fired. A dialog box is presented for each event handler that returns a non-NULL string. The first Cancel response stops the potential navigation, in which case no unload occurs. If there is no Cancel response, the unload proceeds and onunload events fire.

See also get_onbeforeunload


Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.