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

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

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