Name

BeforeUnloadEvent — Event object for unload events

Inherits from

Event

Synopsis

The unload event is triggered on a Window object just before the browser navigates to a new document, and gives a web application the opportunity to ask the user if he is really sure he wants to leave the page. The object passed to unload event handler functions is a BeforeUnloadEvent object. If you want to require the user to confirm that he really wants to leave the page, you do not need to, and should not, call the Window.confirm() method. Instead, return a string from the event handler or set the returnValue of this event object to a string. The string you return or set will be presented to the user in the confirmation dialog the user sees.

See also Event and Window.

Properties

string returnValue

A message to be displayed to the user in a confirmation dialog before navigating away from the page. Leave this property unset if you do not want to display a confirmation dialog.

Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.