The onunload event is not cancelable, because of security reasons.
To display a comfirmation dialog box, where the user can confirm whether he wants to stay or leave the current page, use the onbeforeunload event.
The event object is accessible to all event handlers in all browsers.
The properties of the event object contain additional information about the current event.
To get further details about these properties and the possible event handler registration methods, please see the page for the event object.
This example illustrates the use of the onunload event:
alert ("The current document will be unloaded!");
</script></head><bodyonunload="OnUnLoad ()"><b>Close this window or press F5 to reload the page.</b></body>