beforeunloadLimited availability
The beforeunload event is fired when the current window is about to be unloaded. Typically this is used to display a dialog to confirm if users really want to leave the page when there is unsaved data that would be lost.
Not yet supported in all major browsers — check the table and provide a fallback.
Browser support
DesktopChrome
1+Supportedsince Dec 11, 2008
Current: 155Edge
12+Supportedsince Jul 29, 2015
Current: 154Firefox
1+Supportedsince Nov 9, 2004
Current: 157Safari
1–2Not supported
3+Supportedsince Oct 26, 2007
Current: 27MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155Firefox Android
4+Supportedsince Mar 29, 2011
Current: 157Safari iOS
✕Not supportedup to 27
Current: 27How to use
Not supported in Safari iOS. Use feature detection below and provide a fallback (or a polyfill) for those browsers.
Example
Full syntax and examples are on MDN: BeforeUnloadEvent.
Feature detection
JS · check before using
if ("BeforeUnloadEvent" in globalThis) {
// BeforeUnloadEvent is available
} else {
// load a polyfill or use a fallback
}Documentation (MDN)
Sub-features
Support for each part of the feature (4). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| BeforeUnloadEvent | 30 | 12 | 1.5 | 7 | 30 | 4 | 7 |
| BeforeUnloadEvent.user_interaction | 60 | 79 | 44 | 11 | 60 | 44 | 11 |
| Window.beforeunload_event | 1 | 12 | 1 | 3 | 18 | 4 | ✕ |
| Window.beforeunload_event.preventdefault_activation | 119 | 119 | 6 | 11 | 119 | 6 | ✕ |