Thank you for the answer, but the chat have that already and check for window open every 1 minute, what I was thinking is about something like this:
window.onbeforeunload = confirmExit;
\\ Here -> body return false;
return message to display in dialog box;
With the confirmation alert make the body or the link return false.