The code below is not working for me in Chrome or FireFox. <body onUnload="alert('Dont Leave');"> What I expected the code to do is, create an alert box when I leave the page.
Occurs before the browser unloads the document. 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.
I have a query regarding my application. Whenever user closes browser window accidentally I'd want to do some clean up operations before that. I have used onunload event but problem is this event is
WindowEventHandlers.onunload - Web APIs | MDN
Using this event handler in your page prevents Firefox 1.5 from caching the page in the in-memory bfcache. See Using Firefox 1.5 caching for details. Browsers equipped with pop-up window blockers will ignore all window.open() method calls in onunload event handler functions ...
WindowEventHandlers.onbeforeunload - Web APIs | MDN
The WindowEventHandlers.onbeforeunload event handler property contains the code executed when the beforeunload is sent. This event fires when a window is about to unload its resources.
onbeforeunload Event - W3Schools
The onbeforeunload event occurs when the document is about to be unloaded. This event allows you to display a message in a confirmation dialog box to inform the user whether he/she wants to stay or leave the current page. The default message that appears in the confirmation box, is different in ...