Reputation: 2008
In a certain case, I need to execute a few lines when the user refreshes the page.
Currently I do this with the onbeforeunload
event as shown below, but I am looking for a way to do this without the prompt. I just want it to happen behind the scenes
The solution can be pure JS (preferred) or could be jQuery based.
//to kill the modal incase refresh or page exit
window.onbeforeunload = closingCode;
function closingCode() {
//bunch of functions here to run before refresh/close
window.location.href = window.location.href.split('#')[0]; //remove leftover hash symbol if it exists
return false;
}
Upvotes: 0
Views: 1103
Reputation: 2677
Try this ;)
window.onbeforeunload = function(){
inst.close();
inst.destroy();
window.location.href = window.location.href.split('#')[0]; //remove leftover hash symbol if it exists
return;
}
Upvotes: 1