Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
The returnValue
property of the 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 Event.preventDefault()
on the BeforeUnloadEvent
object, while also setting returnValue
to support legacy cases. See the beforeunload
event reference for detailed up-to-date guidance.