H
H
hollanditkzn2018-03-02 17:12:02
JavaScript
hollanditkzn, 2018-03-02 17:12:02

how to clear cache in js

The question is, I have a code that for some reason always works when you clear the cache, that is, in the browser I reload via Ctrl + F5. But when you just go to the page or reload only F5, the timer does not work

window.onload = function(){
  function timer(){
    let minute = document.getElementById("m").innerHTML + document.getElementById("mm").innerHTML;
    let second = document.getElementById("s").innerHTML + document.getElementById("ss").innerHTML;
    let end = false;

    if(second > 0) second--;
    else {
      second = 59;
      if( minute > 0) minute--;
      else {
        end = true;
      }
    }
    if(end){
      clearInterval(intervalID);
      $('#modalTerm').modal('show');
      $('#modalTerm').on('hide.bs.modal', function () {
          window.location.replace('http://hosttraining/frontend/web/index.php?r=site%2Findex');
      });
      $('.modal-result_test').html('<div class="modal-result_title">К сожалению, Вы не прошли тест.<br/>' +
                        '</div><div class="modal-result_information">Это плохой результат.<br>' +
                        'Этот тест Вы сможете пройти не раньше, чем через 2 недели.<br>' +
                        'Рекомендую Вам не тратить это время зря и основательно подготовиться.</div><div class="modal-result_information">' +
                        'Успехов!' +
                        '</div>');
      console.log("Время истекло");
    } else {
      document.getElementById("m").innerHTML = Math.floor(minute/10);
      document.getElementById("mm").innerHTML = minute % 10;
      document.getElementById("s").innerHTML = Math.floor(second/10);
      document.getElementById("ss").innerHTML = second % 10;
    }
  }
  window.intervalID = setInterval(timer, 1000);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hollanditkzn, 2018-03-06
@hollanditkzn

Remove window.onloadit and everything will work fine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question