forked from mdn/content
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modernize beforeunload event information (mdn#29595)
* Modernize beforeunload event information * Make fixes for wbamberg and dizhang168 comments * Make sure reasons for the code example structure are clearly stated * other small fixes
- Loading branch information
1 parent
afb43c2
commit 26f6807
Showing
3 changed files
with
129 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
files/en-us/web/api/beforeunloadevent/returnvalue/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: "BeforeUnloadEvent: returnValue property" | ||
short-title: returnValue | ||
slug: Web/API/BeforeUnloadEvent/returnValue | ||
page-type: web-api-instance-property | ||
status: | ||
- deprecated | ||
browser-compat: api.BeforeUnloadEvent.returnValue | ||
--- | ||
|
||
{{APIRef("HTML DOM")}} | ||
|
||
The **`returnValue`** property of the | ||
{{domxref("BeforeUnloadEvent")}} interface, when set to a truthy value, triggers a browser-generated confirmation dialog asking users to confirm if they _really_ want to leave the page when they try to close or reload it, or navigate somewhere else. This is intended to help prevent loss of unsaved data. | ||
|
||
> **Note:** `returnValue` is a legacy feature, and best practice is to trigger the dialog by invoking {{domxref("Event.preventDefault()")}} on the `BeforeUnloadEvent` object instead. See the {{domxref("Window/beforeunload_event", "beforeunload")}} event reference for detailed up-to-date guidance. | ||
## Value | ||
|
||
`returnValue` is initialized to an empty string (`""`) value. | ||
|
||
Setting it to just about any [truthy](/en-US/docs/Glossary/Truthy) value will cause the dialog to be triggered on page close/reload, however note that it also requires [sticky activation](/en-US/docs/Glossary/Sticky_activation). In other words, the browser will only show the dialog if the frame or any embedded frame receives a user gesture or user interaction. If the user has never interacted with the page, then there is no user data to save, so no legitimate use case for the dialog. | ||
|
||
> **Note:** A generic browser-specified string is displayed in the dialog. This cannot be controlled by the webpage code. | ||
## Examples | ||
|
||
See the {{domxref("Window/beforeunload_event", "beforeunload")}} event reference page for a best practice example. | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters