I have a chat program, which relies on whether the user is online or not to keep chatting. So I was wondering, is there a way to logout the user when he/she closes the WHOLE browser, not just the one window in like say, Safari, IE or Google Chrome?
Asked
Active
Viewed 1,933 times
2
-
5You should ideally be using heartbeats to see if the user is online or not. What if the user is not closing the browser but their network connectivity is lost? – Ramesh Apr 12 '12 at 01:37
-
Is it fair-game to require [websockets](http://en.wikipedia.org/wiki/Websockets) or [some hackier "comet"-style long-polling](http://en.wikipedia.org/wiki/Comet_(programming))? – sarnold Apr 12 '12 at 01:37
-
Ah, thanks a LOT for the edit sarnold! – Lucas Apr 12 '12 at 01:38
-
2View this thread, it should help you with your answer: http://stackoverflow.com/questions/2839988/php-how-to-destroy-or-unset-session-when-user-close-the-browser-without-clicki – Ryan Potter Apr 12 '12 at 01:38
-
http://stackoverflow.com/q/9450736/575527 – Joseph Apr 12 '12 at 01:39
-
What do you mean by heartbeats, Ramesh? – Lucas Apr 12 '12 at 01:39
-
1I think the reliable solution is on a server side. For example client pings server some period of time (say every half a minute) and if there wasn't ping for a minute the server logs out the user. – Lion Apr 12 '12 at 01:41
-
I agree with Lion. Assuming your chat client will request new messages from the server. So once the client stops sending those requests for a certain period of time he/she is offline. alternatively.. read http://stackoverflow.com/questions/303859/asp-net-and-sessions-new-browser-instance-versus-new-browser-window – rlemon Apr 12 '12 at 01:46
2 Answers
2
There's nothing available via JavaScript which can be used to detect "WHOLE browser" exits. If you need to be notified when a browser has completely exited (even defining this would be non-simplistic), consider developing browser extensions.

Ken Browning
- 28,693
- 6
- 56
- 68
-
seriously? extensions? so instead of solving a JS/PHP problem (which can be solved in JS/PHP), you now suggest the OP to build extensions? how many browsers do you expect there are? – Joseph Apr 12 '12 at 02:12
-
3
1
My browser is google chrome. i have a idea:setttings-the last settings(more settings-the last)--to logout the user when he/she closes the browser,like cookies and so on.

jptiancai
- 23
- 1
- 1
- 8