Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript register window/tab closing event before window/tab close

This has / may have been asked before, but, as far as I remember, the question was not satisfactory answered at that time ^^

How can I register a window or tab closing event with Javascript? I have tried body.onclose and body.onunload, and dozens others whose names I made up myself and thought they might possibly exist, but none of it worked, or, if it did, it only fired after the window or tab has been closed.

Question: Is there any way to register such an event before the window or tab has been closed? It needn't even be compatible with all browsers, as long as it works with Firefox.

like image 558
arik Avatar asked Apr 06 '10 10:04

arik


1 Answers

window.onbeforeunload= …;.

like image 131
kennytm Avatar answered Oct 26 '22 22:10

kennytm