Welcome Guest, Not a member yet? Register   Sign In
Delete session from DB when closing browser
#5

[eluser]Tim Post[/eluser]
[quote author="MaxH24" date="1337937078"]
I did some research and found this.

The unload event is triggered when:

- a link to leave the page is clicked
- a new URL is typed in the address bar
- the forward or back buttons are used
- the browser window is closed
- the page is reloaded

Now I only want to trigger the event when the browser windows is closed.
So, what can I do?
[/quote]

The reason why the window was closed is not disclosed to the event, you only get notification that it happened. It's meant to allow you to prompt the user to finish something that isn't saved prior to deliberately telling your app 'I don't want to save this'.

To get what you want, just maintain a separate table of active users, and use setInterval() in the client to keep it fresh. If a user attempts to login after just closing the browser, they'll only be told that they are already logged in for .. 30 seconds or so (or whatever frequency you use with setInterval()).

I use Redis for this to avoid query overhead, and a simple getJSON() request to keep it simple. It's also convenient to tell the user 'hey, looks like you've lost internet connectivity' if getJSON fails (and possibly do other work like stop websockets / other longpolls).


Messages In This Thread
Delete session from DB when closing browser - by El Forum - 05-24-2012, 05:32 PM
Delete session from DB when closing browser - by El Forum - 05-24-2012, 06:22 PM
Delete session from DB when closing browser - by El Forum - 05-25-2012, 02:11 AM
Delete session from DB when closing browser - by El Forum - 05-25-2012, 09:24 AM
Delete session from DB when closing browser - by El Forum - 05-28-2012, 12:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB