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
- pEvtObj [in]
Type: IHTMLEventObj
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:
- Close the current window.
- Navigate to another location by entering a new address or selecting a Favorite.
- Click an anchor that refers to another document.
- Invoke the anchor.click method.
- Invoke the document.write method.
- Invoke the document.close method.
- Invoke the window.close method.
- Invoke the window.navigate or NavigateAndFind method.
- Invoke the location.replace method.
- Invoke the location.reload method.
- Specify a new value for the location.href property.
- Submit a form to the address specified in the ACTION attribute via the INPUT type=submit control, or invoke the form.submit method.
- Invoke the window.open method, providing the possible value _self for the window name.
- Invoke the document.open method.
- Click the Back, Forward, Refresh, or Home button.
The pEvtObj parameter is required for the following interfaces:
- HTMLAnchorEvents2
- HTMLAreaEvents2
- HTMLButtonElementEvents2
- HTMLControlElementEvents2
- HTMLDocumentEvents2
- HTMLElementEvents2
- HTMLFormElementEvents2
- HTMLImgEvents2
- HTMLFrameSiteEvents2
- HTMLInputFileElementEvents2
- HTMLInputImageEvents2
- HTMLInputTextElementEvents2
- HTMLLabelEvents2
- HTMLLinkElementEvents2
- HTMLMapEvents2
- HTMLMarqueeElementEvents2
- HTMLObjectElementEvents2
- HTMLOptionButtonElementEvents2
- HTMLScriptEvents2
- HTMLSelectElementEvents2
- HTMLStyleElementEvents2
- HTMLTableEvents2
- HTMLTextContainerEvents2
- HTMLWindowEvents2
See also
Reference
Conceptual
Introduction to Data Binding
Build date: 1/23/2012