Very simple question. I need to perform a task when the user closes his browser.
I’m aware of the functions below:
$(window).bind("beforeunload", function() {
return false;
})
$(window).unload(function() {
return false;
})
But both of these – bring up an alert asking the user – “Stay on this page” – “Leave this page” (atleast on Chrome).
I dont want that to happen. I just want to perform a task when he closes it like updating the time on the DB as to when he left.
Any ideas
Thanks
This is impossible to be done cross browser properly since Opera does not actually support it :\ as stated here: cross-browser Onunload and Onbeforeunload ? (particularly opera 11) and in many other well documented places.
Also as others mention there are varying degrees of implementation, for example Firefox you can add your own message to the alert box that shows on beforeunload but in Chrome you cannot and it will just show a generic message of something that does not really make much sense.