Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
How to pause running countdown with button to redirect page?

Already i got this code in javascript

    <script type="text/javascript">
  var count = 20; // Timer
  var redirect = "https://www.instagram.com/"; // Target URL

  function countDown() {
    var timer = document.getElementById("timer"); // Timer ID
    if (count > 0) {
      count--;
      timer.innerHTML = "przekieruje cię za " + count + " sekund."; // Timer Message
      setTimeout("countDown()", 1000);
    } else {
      window.location.href = redirect;
    }
  }
</script>

I would like to place button with pause in my html site - it will works like 'if i press the button while countdown is running it will be stopped, but if i click again it will resume'. I've tried to put clearInterval in code but it didn't work. I'm really an amateur when it comes to javascript.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Nothing special

(async()=>{
    const timer = document.getElementById('timer');

    let timerId;
    let tf = false;
    let k = 7;

    const plusplus = async()=>{
        timer.innerHTML = k + ' dancing cows left';
        if(k < 1)clearInterval(timerId);
        else k--;
    };

    plusplus();
    timerId = setInterval(plusplus, 1000);
    document.getElementById('button').addEventListener('click', ()=>{
        if(!tf)clearInterval(timerId);
        else timerId = setInterval(plusplus, 1000);
        tf = !tf;
    });
})();
<button id="button">stop / resume</button>
<div id="timer"></div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!