The onbeforeunload event is triggered when it is about to leave the current page (refresh or close).
This event can be used to pop up a dialog box that prompts the user to continue browsing the page or leave the current page.
The default message for the dialog box differs depending on the browser, and the standard information is similar to "Are you sure you want to leave this page?" "。 This information cannot be deleted.
But you can customize some message prompts to appear in the dialog box along with the standard information.
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><title>Beginner's Tutorial (runoob.com)</title></Head><Body><P>Close the current window, press F5 or click the following link to contact the onbeforeunload event.</P><ahref= "Http://www.runoob.com">Click to jump to rookie tutorial</a> <Script>Window.onbeforeunload= function(e) {return(e||window.event). ReturnValue= 'have information not saved, confirm leave?! '; }</Script></Body></HTML>
With JS How to judge I have clicked the "Close" button in the form?