OnBeforeUnLoad Event

As the window is closing, windows fire an event before onunload that the user can capture to do “something” before the window closes. Or, just prevent it from closing.

The code:

 window.onbeforeunload = function()

{
    return ‘Prompt message…’;
}