Want to detect a browser close event?

I am working on any application in which I need to determine whether the user will close the tab or browser so that I can disconnect the user from another user, mainly my chat application.

I used: -

window.onbeforeunload = confirmExit;

function confirmExit() { 
    if(needToConfirm) {
        return "Leaving this page will end your conversation.";
    }

Its work is great, when I try to close the browser or tab, it shows a pop-up window with the message "Click OK to continue, or Cancel to stay on the current page." I want to complete the task when the user clicks the OK button, and if he clicks Cancel, he will remain on the current page.

Please help me: (

Thanks in advance

Ansh j

+3
source share
3 answers

It's impossible.

unload AJAX, .

- AJAX x , .

+4

: Unload, . , .

, "" , , , .

, , .

+2

Why not periodically click the β€œserver” so that it knows that they still exist, and if the user skips 3 pings, then it will be marked as logged out?

+1
source

Source: https://habr.com/ru/post/1747205/


All Articles