Q:

log out if all tabs closed

I have an app, and user and session models there. New session creates when user logs in. and sessiond destroyes if user log out or close browser. But I want to add destroying session if user close all tabs with my app. Is it possible to do from scratch? If no what i should use?
Thanks in advance

A:

Session variables are server-side, and tab closing is a client-side action, so you'd have to somehow send a signal to the server to clear those session variables.
The most obvious method to me would be to use the browser's onbeforeunload method and ajaxically send something to the server to clear the session.
Now you have to  find a way how you will detect all the tabs of your site is closed.Because, if I have your site open in two tabs, this technique will clear the session on the close of the one tab, rendering the other tab useless (not usesless, just the rug might have been pulled from under this page, now that session is gone)

