Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda