Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
Disable a button for some hours with countdown in javascript

I want the button to be disabled after clicking it for 1 hr with displaying the countdown for current logged in user, is it possible to store time in firebase? And retrieve it and i want the time to be continue even the client refreshes the site. Any ideas or suggestions

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

For your initial question (without Firebase), here is a quick example

const button = document.querySelector('#mybutton');
let sec = 5;
let countdown = null;

const updateButton = () => {
  button.innerHTML = `wait ${sec}s`;
  
  if (sec === 0) {
    clearInterval(countdown);
    sec = 5;
    button.innerHTML = 'Click me';
    button.disabled = false;
    return;
  }

  sec--;
}

button.onclick = () => {
  button.disabled = true;
  updateButton();
  countdown = setInterval(function() {
    updateButton();
  }, 1000);
}
<button id="mybutton">Click me</button>

I guess you could make calls to Firebase when you init the sec variable and when you update it, but you could just use local storage for that as you would not add any security using Firebase to prevent any request to be sent.

about 4 years ago · Juan Pablo Isaza Relatório

0

Store the timer inside the browser storage and create a setTimeout on click or on browser refresh by picking up the remaining milliseconds from the browser.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda