I have a web page that calls a post request just before the user tries to exit the page. I am using the window.onbeforeunload
event to achieve that. It works when I leave the page a few seconds after I enter the page, but it doesn't when I stay idle for a few minutes. Here's my Javascript:
window.onbeforeunload = function() {
$.post('http://52.91.227.233:1000/set_day',
{username: user, useday: day}
);
};
According to my observation, there's no problem with the post request or the NodeJS app. It is a problem in the onbeforeunload
event, though I don't know what exactly the problem is. I've also tried beforeunload
but it still doesn't work
Thanks!