Описание тега onbeforeunload

The onbeforeunload event is triggered before a user navigates away. This event listener can be used to show a confirmation dialog to the user on page leave.

The onbeforeunload event is triggered before a user navigates away. This event listener can be used to show a confirmation dialog to the user on page leave.

In most browsers, the return value of the onbeforeunload event is displayed in the dialog, together with a default message. Since Firefox 4, this value is not displayed any more.

Example

window.onbeforeunload = function(e) {
    return 'Dialog text here.';
};

See also: