开发者

onunload is not working without a call to function alert?

开发者 https://www.devze.com 2023-04-05 02:26 出处:网络
Lets say I\'m trying to do the following: window.onunload = handleOnClose; function handleOnClose() { logout();

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 开发者_StackOverflow中文版on unload. But it doesn't seem to go in the handleOnClose function at all if I remove the alert function.


Add return ""; maybe ?:

window.attachEvent( "onunload", function(event) {
this_function_works(); // must be synchronous
event.preventDefault ? event.preventDefault() : event.returnValue = false;
}); 

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消