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
source
share