The implementation is relatively simple as follows
window.onbeforeunload = function() {
return "Are you sure you want to leave the page?";
}
There is another way to write it
window.onbeforeunload = function(event) {
(event || window.event).returnValue = "Are you sure to exit?";
}
This method is not supported by chrome and safari, but due to the support of ie and ff, html5 has also joined the standard...
Everyone knows that several pop-up dialog boxes in browsers will be blocked The event proceeds (such as alert, confirm), and the event will continue to execute after further operations
The general approach is like this
window.onbeforeunload = function(event) {
return confirm("Are you sure to exit?");
}
This will pop up twice, and the content after return will be used as a prompt to leave the page..