質問

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

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top