BeforeUnloadEvent: returnValue property - Web APIs | MDN

Value

returnValue is initialized to an empty string ("") value.

Setting it to just about any truthy value will cause the dialog to be triggered on page close/reload, however note that it also requires 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 beforeunload event reference page for a best practice example.

Specifications

Specification
HTML
# dom-beforeunloadevent-returnvalue

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.