Possible Duplicate:
how to check users leave a page
For example when somebody refreshes, enters a new URL into the location bar, or navigates away using a link on the page?
I need to do some work after someone attempts to leave my page.
EDIT: onunload doesn't work because in most browsers that doesn't execute until the page they are attempting to leave to returns a response. I want to execute some code as soon as they attempt to leave.
beforeunload appears to work, but I'm not sure a beforeunload without a return is proper form.