[jQuery] intercept navigation away from page?

[jQuery] intercept navigation away from page?


i have a modal window and when the "close" button gets clicked i log
the time and date the user closed the modal.
but what about if he just closes the browser or directly navigates to
another page?
is there any way to implement "cleanup" stuff here?
thanks