AlexC
AlexC

Reputation: 9661

Capture event onclose browser

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

Upvotes: 23

Views: 125716

Answers (4)

Brunno
Brunno

Reputation: 5

Men, use this:

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

Upvotes: -1

Pavel Hodek
Pavel Hodek

Reputation: 14597

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?

Upvotes: 3

Jonathan Fingland
Jonathan Fingland

Reputation: 57167

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)

Upvotes: 9

jeroen.verhoest
jeroen.verhoest

Reputation: 5183

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

jQuery:

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

or javascript:

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

Upvotes: 16

Related Questions