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

172
Views
¿Cómo pausar la cuenta regresiva con el botón para redirigir la página?

Ya tengo este código en 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>

Me gustaría colocar el botón con pausa en mi sitio html; funcionará como 'si presiono el botón mientras se ejecuta la cuenta regresiva, se detendrá, pero si hago clic nuevamente, se reanudará'. Intenté poner clearInterval en el código pero no funcionó. Soy realmente un aficionado cuando se trata de javascript.

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

0

Nada especial

 (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!