Home > Web Front-end > JS Tutorial > js implementation code for prompt before closing the page_javascript skills

js implementation code for prompt before closing the page_javascript skills

WBOY
Release: 2016-05-16 18:06:18
Original
1181 people have browsed it

The implementation is relatively simple as follows

Copy code The code is as follows:

window.onbeforeunload = function() {
 return "Are you sure you want to leave the page?";
}

There is another way to write it
Copy code The code is as follows:

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
Copy code The code is as follows:

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..
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template