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

153
Visualizações
Click on a button and start Time counting on redirected page (JavaScript)

I am trying to develop a quiz app with Django. Where I want to add a functionality like this - "When the users will click on start test button, they will be redirected to the questions page, and exam time will be started". Here I am using JavaScript "setInterval" to count time. It's working on the same page, but it's not working on the redirected page.

My Js code :

var check = null;

function printDuration() {
    if (check == null) {
        var cnt = 0;

        check = setInterval(function () {
            cnt += 1;
            document.getElementById("para").innerHTML = cnt;
        }, 1000);
    }
}

function stop() {
    clearInterval(check);
    check = null;
    document.getElementById("para").innerHTML = '0';
}

console.log("Time counting... ... ...")

Button

<a href="{% url 'test' %}" class="btn btn-primary mt-5"id="btnStart" type="button" value="Start"
    onclick="printDuration();">Start Test</a>

Redirected page code: , here time counting will be started:

<h2 class="pb-5">Welcome to test page</h2>
    <p id="para">0</p>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If I understand correctly, the timer is on the page before redirect. When you go to a new url, everything reloads including the JavaScript. Everything from the previous page including your timer is removed. You'll have to make a new timer in the redirected page

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