The implementation is as follows:
CopyCodeThe Code is as follows: window. onbeforeunload = function (){
Return "are you sure you want to leave the page? ";
}
There is also a way to writeCopy codeThe Code is as follows: window. onbeforeunload = function (event ){
(Event | window. Event). returnvalue = "are you sure you want to exit ";
}
This method is not supported by chrome and Safari, but because of the support of IE and FF, HTML5 is also added to the standard...
As we all know, the events (such as alert and confirm) will be blocked in the pop-up dialog box of the browser. After further operations, the events will continue to be executed.
This is common practice.Copy codeThe Code is as follows: window. onbeforeunload = function (event ){
Return confirm ("are you sure you want to exit ");
}
Here we will pop up two times, and the content after return will serve as a prompt for whether to leave the page ..