Node JS Chat – Tell if navigation to page or closing window

I am adding a Node JS Chat to my website. At the moment I am clearing the user from the chat if they close the window using the following JQuery method:

$  (window).unload(function () {
  jQuery.get("/leave", {id: session.id});
});

This works perfectly and tells the node JS server that the user has closed the window, however this also removes the user from the chat room if they navigate to another page on the website. Is there a way I can tell if they go to another page on the domain and not remove them from the chat? At the moment when they navigate to another page it is being treated as if they are closing the window.

Cheers

Eef

newest questions tagged jquery – Stack Overflow

About Admin