Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

306
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!