Lets say I’m trying to do the following:
window.onunload = handleOnClose;
function handleOnClose()
{
logout();
// alert('You have been signed out.');
}
It goes into the handleOnClose if I use the alert function. I don’t want to alert any messages on unload. But it doesn’t seem to go in the handleOnClose function at all if I remove the alert function.
Add
return "";maybe ?:And make sure
logout()is executing before page closes. Meaning, you are not trying to do AJAX calls here, or submit forms. You can set or clean cookies or localStorage.