I am trying to send a post to my server when a user either closes their browser or closes a window.
This is what I have so far:
$(window).unload(function(){
$.post('/offline', {account_id: ACCOUNT_ID});
});
However, this only seems to work when a user enters a new url in the current window.
In addition to whenever a user enters a new url in a window, I need to send a post to the server when the browser or window is closed.
Anyone know what the problem is?
Thank you.
Update:
I think the above javascript will work for me, however, this occurs for every event on the website. For example, clicking a link.
Is it possible to to only trigger this if a user enters a new url or closes the window?