want to detect browser close event?

后端 未结 3 1734
渐次进展
渐次进展 2021-01-21 06:40

I am working on any application in which i need to detect that whether user close the tab or browser so I can disconnect the user from other user basically its an chat applicati

3条回答
  •  一生所求
    2021-01-21 07:43

    Go the other way around: when you receive the Unload event, send the server a message that informs the user is about to disconnect. The server waits for some time and then automatically disconnects.

    Then, if the user click cancel and stays on the page, you send a message to the server to inform that the client is still alive.

    The downside is that, if the user waits too long to click cancel, he might be disconnected.

提交回复
热议问题