0

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;
}
GWR
  • 1,878
  • 4
  • 26
  • 44

1 Answers1

1

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;
}
itzmukeshy7
  • 2,669
  • 1
  • 21
  • 29