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..
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn