8

I am developing a web application , in that I want to log out the user ,only when he closes all the 'tabs' of my application or user closes the browser .

Does anyone know how to do it ?

Mariselvam
  • 1,093
  • 2
  • 15
  • 28
  • 1
    This has come up before, and the only realistic way is to track how many are open and "pinging back" on a regular basis, with possibly an `onunload` to signal one has been closed. You can't detect the actual tabs themselves in Javascript, though. You don't have access to tabs in Javascript. You can use a ping from the browser to keep the session alive, with an aggressive (1-3 minute timeout, for instance) session timeout. – Jared Farrish Dec 03 '11 at 10:56
  • Check out here: http://stackoverflow.com/questions/1921941/close-kill-the-session-when-the-browser-or-tab-is-closed – Devnook Dec 03 '11 at 19:14

1 Answers1

1

Try the answer here: Javascript Communication Between Browser Tabs/Windows. Cookies are the usual way to do this. Combine those with the "onunload" event and you should be able to accomplish what you need.

Would be easier, though to simply set your login cookie as "session" by setting the lifetime to 0. This is shared between tabs in most of the browsers I have used and is cleared when the window closes. Only problem is that Internet Explorer tends not to clear session cookies unless the window is closed, not when all tabs of a website are closed.

Community
  • 1
  • 1
Reid Johnson
  • 1,394
  • 14
  • 20