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

122
Visualizações
Redirect after countdown ends

Currently, I have this in my HTML code and am not 100% sure on how to redirect to another page I have after the countdown finishes. I am not too familiar with javascript at the moment either, any help is appreciated. I know that when the page loads it takes the current time ( at the .now snippet) and just adds 10 seconds to it rather than a set time the script should end at then display the difference between present and that set time. The issue with this is that when anyone loads this page it would always show a countdown for 10 seconds to it rather than a universal countdown. For example, the time currently is 3:53 and should end at 4:00. Once the time hits 4 push the redirect.

  <!--Countdown Script -->
  <script type="text/javascript">
    $(document).ready(function() {
      $('#countdown17').ClassyCountdown({
          theme: "flat-colors-very-wide",
          end: $.now() + 10
      });
    });
  </script>
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You want to get the time from a fixed one. So, utilize Date built-in API instead of jQuery's $.now(), because

This API has been deprecated in jQuery 3.3; please use the native Date.now() method instead.

What time do you want? Determine it beforehand (GMT):

const date1 = new Date('September 13, 2021 04:00:00');

Then, when subtracting the dates you'll get the time remaining.

  <!--Countdown Script -->
  <script type="text/javascript">
    $(document).ready(function() {
      $('#countdown17').ClassyCountdown({
          theme: "flat-colors-very-wide",
          end: date1 - new Date() // gets the difference between determined date and current date
          onEndCallback: () => {
            window.location.href = "http://www.example.com";
          }
      });
    });
  </script>

Remember to handle the case when the time of access was after the pre-defined time.

about 4 years ago · Juan Pablo Isaza Relatório

0

I'm assuming this is the ClassyCountdown() jQuery plugin you are using: https://github.com/arsensokolov/jquery.classycountdown

If that's the case, it has an onEndCallback which is called once the countdown reaches 0.

So your code would become something like this:

  <!--Countdown Script -->
  <script type="text/javascript">
    $(document).ready(function() {
      $('#countdown17').ClassyCountdown({
          theme: "flat-colors-very-wide",
          end: $.now() + 10,
          onEndCallback: function () {
             document.location.href = 'https://www.google.com' // <- The url to redirect to
          }
      });
    });
  </script>

Updated answer to redirect at an absolute time:

$(document).ready(function() {
  setInterval(function() {
    // This is when you want the redirect to happen
    // This is the absolute time, as reported by the users browser
    let hour = 21;
    let minute = 18;
    let second = 20;
    
    let date = new Date();
    
    if (date.getHours() == hour && date.getMinutes() == minute && date.getSeconds() >= second) {            
      document.location.href = 'https://www.whatever.com';
    }    
  }, 1000);      
});
about 4 years ago · Juan Pablo Isaza Relatório

0

add a callback parameter (function) to your countdown

<!--Countdown Script -->
<script type="text/javascript">
$('#countdown17').ClassyCountdown({
    theme: "flat-colors-very-wide",
    end: $.now() + 10,
    onEndCallback: function () {
        window.location.href = "http://www.newlink.com";
    }
});
</script>
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