This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The BeforeUnloadEvent interface represents the event object for the beforeunload event, which is fired when the current window, contained document, and associated resources are about to be unloaded.
See the beforeunload event reference for detailed guidance on using this event.
Inherits properties from its parent, Event.
returnValue Deprecated
When set to a truthy value, triggers a browser-controlled confirmation dialog asking users to confirm if they want to leave the page when they try to close or reload it. This is a legacy feature, and best practice is to trigger the dialog by invoking event.preventDefault(), while also setting returnValue to support legacy cases.
Inherits methods from its parent, Event.
| Specification |
|---|
| HTML> # the-beforeunloadevent-interface> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
BeforeUnloadEvent |
30 | 12 | 1.5 | 17 | 7 | 30 | 4 | 18 | 7 | 3.0 | 4.4 | 7 |
returnValue |
11930–119Before Chrome 119, an empty string incorrectly activated the confirmation dialog. |
12 | 1.5 | 10517–105Before Opera 105, an empty string incorrectly activated the confirmation dialog. |
7 | 11930–119Before Chrome Android 119, an empty string incorrectly activated the confirmation dialog. |
4 | 7918–79Before Opera Android 79, an empty string incorrectly activated the confirmation dialog. |
7 | 3.0 | 1194.4–119Before WebView Android 119, an empty string incorrectly activated the confirmation dialog. |
7 |
user_interaction |
60 | 79 | 44 | 47 | 11 | 60 | 44 | 44 | 11 | 8.0 | 60 | 11 |
beforeunload event
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/BeforeUnloadEvent