0

In Chrome the timer is working fine but in Safari it pauses when the tab or window is inactive. I want it to keep running even when not active.

What am I missing? or can anyone help me tweak my script

jQuery(document).ready(function() {
  const startingMinutes = 15;
  let time = startingMinutes * 60;
  const countdownEl = document.getElementById('countdown');
  var myInterval = setInterval(updateCountdown, 1000);

  /* jQuery("input.ays_next.action-button").attr('disabled','disabled'); */

  /* jQuery("input.ays_next.action-button").click(function() {
    if(jQuery("[data-question-id=5]").css('display') == 'flex') {
        jQuery("input.ays_next.action-button").attr('disabled','disabled');
        alert("The paragraph was clicked.");
    }
  }); */

  function updateCountdown() {
    const minutes = Math.floor(time / 60);
    let seconds = time % 60;

    seconds = seconds < 10 ? '0' + seconds : seconds;

    countdownEl.innerHTML = `${minutes}: ${seconds}`;
    time--;
    time = time < 0 ? 0 : time;

    /* if(jQuery("[data-question-id=5]").css('display') == 'flex') {    
    } */
    if (time == 0) {
      jQuery("input.ays_next.action-button").removeAttr('disabled');
    }
  }

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span id="countdown" style="color: #f0b62e;">14: 35</span>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Sarah Blo
  • 23
  • 3

0 Answers0