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

305
Vistas
Remember if button was clicked + Stop interval doesnt work

so I'm trying to create two buttons. One is refreshing site on interval and second one should stop it after pressing, but the stop button isn't working. Second thing is that if I press start button it's not saved in local storage as I want it. Could you guys help me with this?

window.onload = function () {
    if (localStorage.getItem("refresh")) {
        startref()
    }
};

    function startref() {
        let intervalId = setInterval(function () {
                chrome.tabs.query({ active: true, currentWindow: true }, function (arrayOfTabs) {
                 var code = 'window.location.reload();';
                 chrome.tabs.executeScript(arrayOfTabs[0].id, { code: code });


            });
        
        }, 1000);
        localStorage.setItem('refresh');
    }

function stop() {
    clearInterval(intervalId);
}

document.addEventListener('DOMContentLoaded', function () {
    document.getElementById("startbtn").addEventListener('click', startref);

});


document.addEventListener('DOMContentLoaded', function () {
    document.getElementById("stopbtn").addEventListener('click', stop);

});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

localStorage.setItem function takes two arguments. One is key and another is the value for the key.

change this line

localStorage.setItem('refresh');

into this

localStorage.setItem('refresh',intervalId);

When you clear the interval first get the intervalId stored in the localStorage and then call clearInterval.

function stop() {
    const intervalId = localStorage.getItem("refresh");
    clearInterval(intervalId);
}

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