Question

Im preparing an online quiz , and prevent that from unloading by onbeforeunload js object , after the time will up , I want to redirect the page to report page , but I cant cancel onbeforeunload event ! is anyone knows a trick for it ?

var isPostback = false;
window.onbeforeunload = unloading;
function unloading() {
  if (!isPostback) {
    return 'Caution: The timer will not be paused.';
  }
}

I want to cancel above event after the time's up

Was it helpful?

Solution

In the callback for the timer, you could set window.onbeforeunload = null to remove the handler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top