Search code examples
javascriptjqueryonunload

JavaScript: How to abort unload and making a JavaScript call?


I'd like to make at evere onunload event a jQuery call which toggles a few divs in one second. And then I'd like to do the unload.

How can I time out the unload for one second and make a jQuery call in this time?

Thanks for help!

Flo

EDIT:

Ok, I think, the most passable solution is instead of an usual link every link gets a javascript call like this:

<a href="link('http://google.ch')">Google</a>

And the Function link:

function link(param) {
    //Here a for loop to toggle all the divs what I wanted before...
    window.location=param;
}

But thanks for help ;)


Solution

  • beforeunload's event can only be halted with a blocking action such as alert(), prompt(), etc...

    So if you tried to call a function in that event, it is most likely the browser will simply ignore it.