Share via


onbeforeunload event

[This documentation is preliminary and is subject to change.]

Fires prior to a document being unloaded.

Syntax

HTML Attribute <element onbeforeunload = "handler(event)">
Event Property object.onbeforeunload = handler;
attachEvent Method object.attachEvent("onbeforeunload", handler)
addEventListener Method object.addEventListener("beforeunload", handler, useCapture)

Standards information

There are no standards that apply here.

Event information

Synchronous No
Bubbles No
Cancelable No

Event handler parameters

Remarks

When a string is assigned to the returnValue property of window.event, a dialog box appears that gives users the option to stay on the current document and retain the string that was assigned to it. The default statement that appears in the dialog box, "Are you sure you want to navigate away from this page? ... Press OK to continue, or Cancel to stay on the current page.", cannot be removed or altered.

When you assign a string to the returnValue property of window.event and the Windows.ApplicationModel.ApplicationExecutionState is running, a dialog box appears that gives users the option to cancel or continue. The default statement that appears in the dialog box, "Are you sure you want to navigate away from this page? ... Press OK to continue, or Cancel to stay on the current page.", cannot be removed or altered.

When you return null, false, undefined, or nothing from the returnValue property of this event handler, the WWAHost.exe calls the onunload event handler.

When you return true from the returnValue property of this event handler and the Windows.ApplicationModel.ApplicationExecutionState is running, the WWAHost.exe does not display a prompt to the user. It cancels navigation without calling onunload. Instead, you must provide an alternate user interface (UI) to the user to cancel navigation.

When you return some value from this event handler and the Windows.ApplicationModel.ApplicationExecutionState is notRunning, WWAHost.exe ignores the return value and calls the onunload event handler.

Until the user closes WWAHost.exe, you have complete control over the user experience for navigation.

Signals that the document is about to be unloaded.

To invoke this event, do one of the following:

The pEvtObj parameter is required for the following interfaces:

See also

Reference

onload

onunload

Conceptual

Introduction to Data Binding

 

 

Build date: 1/23/2012