Capture event onclose browser

How I can capture event, close browser window, in jQuery or javascript ?

http://docs.jquery.com/Events/unload#fn

jQuery:

$(window).unload( function () { alert("Bye now!"); } );

or javascript:

window.onunload = function(){alert("Bye now!");}

You’re looking for the onclose event.

see: https://developer.mozilla.org/en/DOM/window.onclose

note that not all browsers support this (for example firefox 2)

Events onunload or onbeforeunload you can’t use directly – they do not differ between window close, page refresh, form submit, link click or url change.

The only working solution is How to capture the browser window close event?

Men, use this:

if(myWindow.closed){
    callback();
    return;
}


The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   Can I trigger JavaScript's garbage collection?

Similar Posts