I am trying to write a jQuery plugin that should logout the user before leaving the page or closing the browser. I have captured every exit point of the page (eg. f5, close tab, refresh, close browser, navigate) but when I try to send a jQuery.post() request before leaving the page, the request can not be made because the browser has no time to send the request.
Is there a way to delay any page navigation / page leaving / browser closing by 1 seconds or more so I can squeeze in a jQuery.post() request before actually leaving the page?
The traditional way to do this is to have the client send a request to the server every
xminutes, to let it know the user is still active. If the server does not receive a request within a certain timeframe, it should expire the session (thus logging the user out).