开发者

onunload is not working without a call to function alert?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜