Is the window object onclose() or closing() event exposed in HTML/Javascript?
Asked
Active
Viewed 1.6k times
4 Answers
4
You have both onunload() and onbeforeunload() javascript events for that.

Romain Linsolas
- 79,475
- 49
- 202
- 273
-
2Just note that if you call a function that is declared on the closing page itself, you **must** use `onbeforeunload`. If you try to use `onunload`, the function you are calling does no longer exists... – awe Apr 12 '11 at 08:08
0
There is no event that lets you determine the difference between a page refresh, form submission, link clicked, or browser closed.
I am guessing that is what you are really after.

epascarello
- 204,599
- 20
- 195
- 236
0
As suggested epascarello: 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?
Popup windows are problematic (bring to front, close event, blocking) and annoying - you should consider using a modal popup instead.

Community
- 1
- 1

Pavel Hodek
- 14,319
- 3
- 32
- 37