I want to save an unload event to execute it later on. For example:
// on unload do nothing but safe the event
jQuery(window).unload(function() {
// TODO safe the unload event here somehow
// unloadEvent = this;
return false;
});
Later, another piece of code should be able to perform the previously saved event, for example like this:
function finallyUnload() {
// TODO
// unloadEvent.perform();
}
Is there any way to do this?
Update
My browser window is communicating with a Java Selenium application and needs to wait until it received the information about the unload event and how it happened. When that's the case, the unload event can be executed.
I understood that unload events cannot be delayed or stopped, so i got another idea. What about intercepting all clicks on links with href and buttons, also submissions of forms. Then i manually set window.location
to the desired URL or submit the form. Could that work?