When ever user leaves chat page (Either by logging out or just by simple closing the browser window). Chat script instantly detects that user left and show offline sign. Thi
The chat can send a logout message using the onunload
event, which is triggered if the user leaves the page/closes the browser, however it is not reliable. A second option for the server is to begin a timeout countdown as soon as the underlying TCP connection is closed and show the user as "offline" in case he does not reconnect in time.