Вопрос

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