Javascript: do something before window or tab is closed

Last day while I was in the middle of developing a website, there was a situation encountered which made me to handle the window closing event. This can be handled using the following event.

window.onbeforeunload

The usage is like


window.onbeforeunload = function ()
{
        alert('I am gonna close');

 }



Yep. That's all.

Comments