Before the user leaves the page, prompts to leave this page (including browser button events)
<script type= "Text/javascript" > window.onbeforeunload = function () {
Return "Your article has not been saved. ";
}
</script>
If you need to eject a dialog box when you exit the page, prompt the user to exit the page, similar to setting a feature without saving the page. This implementation of the method is relatively simple, the most common is the use of unload events, but this implementation has a disadvantage, is whether to agree or not, the result is the same, will exit the page, therefore, if you want to pop-up dialog box, there are users can choose the space, if you are sure to exit, otherwise do not close the page, the effect chart is as follows:
The onbeforeunload () event is recommended here, which means that the method executed before loading the Unload event is used as follows:
<script type= "Text/javascript" >
Window.onbeforeunload = function () {
Return "Will you be sure you want to exit the page?" ";
}
</script> This will pop up a dialog box, only confirmation will exit the page.
Window.onbeforeunload can be combined with jquery implementation when the user set the page without saving the hint effect, that is, if the saved should not prompt the dialog box, you can use the following methods, when you do not need
Prompt dialog box:
<script type= "Text/javascript" >
Window.onbeforeunload = function () {
Return
}
</script> This will exit the page directly without any dialog boxes popping up.
Combining jquery to implement JavaScript exit page Pop-up dialog box is the combination of the above two methods, when the page satisfies a situation, if you need to pop up a dialog box pops up, otherwise not pop-up dialog box, so very convenient, jquery has its own Unload method, but also can not achieve return , there is only one result, that is to exit the page, so combining window.onbeforeunload will be able to implement an Exit page Pop-up dialog box function.