Onbeforeunload event is prompted when the browser is closed


Onbeforeunload event it is used like this:

<script language="javascript"
    g_blnCheckUnload = true; 
    function RunOnBeforeUnload() {     
        if (g_blnCheckUnload) {
        window.event.returnValue = 'You will lose any unsaved content';       
        }   
    }
</script>
<body  onbeforeunload="RunOnBeforeUnload()">
</body>

This causes the onbeforeunload event to be triggered every time the browser window is closed or a new page is flushed.

Extract as follows: onbeforeunload event:

Usage:

Object. Onbeforeunload = handler < Element onbeforeunload = “handler”… > < / element> Description: when the event is triggered, a dialog box with “ok” and “cancel” will pop up. The handler can set a return value as the display text for the dialog.

Triggered by:

Close the browser window When going to another page through the address bar or favorites Click back, forward, refresh, one of the home pages When clicking on a url to link to another page When any of the following events are called: click, document write, document open, document close, window close, window write, window NavigateAndFind,location replace,location reload,form submit. When you open a page with window open and pass the name of the window on that page to the page you want to open. When you re-assign the value of location.href. When submitting a form with the specified action via the input type= “submit” button. It can be used in the following elements: BODY, FRAMESET, window