Verification of user's existence in chat script

后端 未结 3 1682
一个人的身影
一个人的身影 2020-12-18 13:36

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

3条回答
  •  难免孤独
    2020-12-18 14:28

    Just have your JavaScript chat code send a message to the server every 2 seconds using XMLHttpRequest. When you don't receive a message, that means that the user has closed the window.

提交回复
热议问题