Skip to Content
Platform.Ontology

Leave-page confirmation (beforeunload)

Shows a generic Leave site? dialog, only if the person interacted with the page.

Does something on your deviceThings a page can doWindows and navigationWeb browsersWhile you use it

In one line

Can show a generic Leave site? warning when you close or leave, after you have interacted

Shows a generic Leave site? dialog, only if the person interacted with the page.

A site can ask the person to confirm closing or leaving, often to protect unsaved work. Browsers hide the site's own text, so it cannot scare people with custom messages.

What it can and can't do

What the user does: You click, tap or type on the page, then try to close or leave it

It can

  • Show a Leave site? box to protect your unsaved work
  • Show it when you close the tab or window
  • Show it when you press back or go to another site

It cannot

  • Show custom text, since browsers hide the site's own message
  • Show the box if you have not touched the page
  • Block you for good, since you can still leave
  • Work on iPhone browsers

How it differs between platforms: Works in Chrome, Edge, Firefox and Safari on computers. iPhone browsers do not show it.

Browser support

BrowserStatusFirst versionReleasedNote
ChromeSupported12008-12-11None
EdgeSupported122015-07-29None
FirefoxSupported12004-11-09None
SafariSupported32007-10-26None
Safari on iPhoneNot supportedNot availableNot listedNone
Chrome on AndroidSupported182012-06-27None
Samsung InternetSupported1.02013-04-27None

How a site asks for it

APIwindow.addEventListener('beforeunload', e => { e.preventDefault(); e.returnValue = ''; })
Browser compat keysapi.Window.beforeunload_event
api.BeforeUnloadEvent
How access is grantedgesture
What the user seesNo prompt (needs a click, tap or keypress)
Needs a secure context (HTTPS)No
Needs a user gestureYes
Activationsticky
How long it lastsFires on each unload attempt while the listener exists
How to take it backNothing to revoke (no permission is stored)
Inside an iframeDialog suppressed in cross-origin iframes without activation

Typical flow

  1. Person interacts with the page (sticky activation)
  2. Page registers beforeunload and sets returnValue
  3. On close or navigate, browser shows generic confirmation

Data you get

Shape: none

No individual data fields. The signal is the access itself.

Technical limits

  • Needs sticky user activation: no dialog if the page was never clicked or typed in (Chrome 60)
  • Custom message text is ignored (Chrome 51, Firefox 44, Safari 9.1)
  • Cannot run async work or block navigation indefinitely: dialog is the only block
  • A beforeunload listener makes a page ineligible for the back/forward cache in Chrome desktop and Firefox
  • Not reliable on mobile: tab discard and app switch skip it; use pagehide and visibilitychange

The story

What it is

A page can show a generic Are you sure you want to leave dialog, only after you used the page.

For you

If you try to close a page with unsaved work, a box asks Leave site? You can stay or leave. Pages you never touched cannot show it.

For makers

Makers use it to protect unsaved work in forms, editors and checkouts. Browsers use a fixed message to stop it being used to trap people. Misuse by scam sites is limited by the click rule.

Where you see it

TypeExampleApps
productivityA web editor like Google Docs warns you if edits are not saved yet when you close the tab.Google Docs
shoppingA checkout page asks if you want to leave with items in your cart and a half filled form.None named
gamesA browser game asks before you leave a ranked match where leaving counts as a loss.None named
creativeA web design tool warns about unsynced changes.Figma
educationA test platform warns a student before they close an exam.None named
bankingA bank page warns you before you leave a half finished transfer.None named
securityA scam page tries to trap you with repeated Leave prompts, but browsers allow it only after you click.None named

Risks

  • Can trap users
  • Annoying prompts

What the platform says

Good uses and abuse

Legitimate uses

  • Unsaved form or document warning

Known abuse

  • Retention dark pattern
  • Exit-intent friction

Scores

ScoreValueMeaning
Sensitivity1 of 5How revealing the data is
Utility4 of 5How useful it is to honest apps
Friction0 of 5How much the user has to do
Fingerprint bitsNot ratedRough identifying entropy, when known

History

  • 2016-01, Firefox 44: Custom message removed
  • 2016-05, Chrome 51: Custom beforeunload message removed
  • 2017-07, Chrome 60: Dialog requires user interaction with the page

Sources

How well checked: Based on official documentation.

On this page