This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

returnValue

Summary

Gets or sets a value that indicates whether to warn the user prior to navigating away from a page.

Property of dom/BeforeUnloadEventdom/BeforeUnloadEvent

Syntax

var returnValue = event.returnValue;
event.returnValue = preventNavigationReason;

Return Value

Returns an object of type StringString

The text that will be shown to the user.

Examples

//set returnValue to custom string
window.onbeforeunload = function (e) {
    e.returnValue = "About to navigate away from this page";
};

Usage

 The BeforeUnloadEvent allows you to warn a user who is navigating away from a page or closing the browser. Set the return value to false or a string value to cancel the document unload event. You can also return a string or Boolean value from the event handler to display a message to the user, who is asked to confirm that they want to unload the document.

Related specifications

HTML5
Working Draft
WHATWG HTML
Living Standard

Attributions