0

I have a system where I need to know when the browser is closed in one file. This file is created and destroyed number of times in one session. I can get control in window.onbeforeunload event when the browser is closed as well as when the file is destroyed. I need to know when the browser is closed. I need to fire logout event on server when the browser is closed and not every time when the file is destroyed. I need to know this in the same file. How can I know in the same event weather the browser has been closed or the file has been destroyed and it has fired unload event. What I have tried is :

window.onbeforeunload = function(e) {
    var e = e || window.event;
    if (!(e.clientY > 0) || e.altKey) {
        //Logout event
    }
}

This causes logout every time the unload event is fired and not only when the browser is called.

Any help will be appreciated. Thanks in advance...

hennes
  • 9,147
  • 4
  • 43
  • 63
Deep
  • 5
  • 4
  • Whenever a user is closing the browser - it's not your business. There is no "onClose" event. Automatic logoff can only be achieved by timeouts server side. – Axel Amthor Sep 04 '14 at 14:11
  • Yes True. The problem that I am facing is that server side timeout is 60 minutes and if user tries to login within that time period, system will not allow to login as concurrent sessions for the same user have been disabled. If anything you can suggest, it will be helpful. Thanks. – Deep Sep 05 '14 at 04:03

1 Answers1

0

According to your last comment:

  • You may set a unique persistent cookie on the client. This cookie is unique for each client (don't use the IP address)
  • This cookie is stored along with the session currently running.

When the user closes it's browser and reopens it, the session cookie is gone. The client cookie is still valid and will be sent.

Now you may check, whether the user is logging in from the same client by checking the client cookie value just send against the one stored in the lingering session and you may even be able to "reinitialize" this session again.

This would even work, if the user is trying to open another browser instance (IE and FF) since each browser would have it's own unique cookie value. enter image description here

Axel Amthor
  • 10,980
  • 1
  • 25
  • 44