Redirect with timer and localStorage

0

I am trying to make a code in JS and when I enter the page index.html redirects to page teste.html and in the test I will click on a close where it will go back to index and in the case now it has to stay in the index, time counter will re-execute the redirect code for teste.html

Follow my code below ..

function openColorBox() {
  window.location.href = 'teste.html';
}

function countDown() {
  seconds—
  $("#seconds").text(seconds);
  if (seconds === 5) {
    openColorBox();
    clearInterval(i);
  }
}

var seconds = 5,
    i = setInterval(countDown, 2 * 420000);

Another attempt

function openColorBox() {
  window.location.href = 'landing.html';
}

function countDown() {
  seconds—
  $("#seconds").text(seconds);
  if (seconds === 5) {
    if (localStorage.getItem("hora") - Date.now() > time_restart) {
      localStorage.setItem("hora", Date.now());
      openColorBox();
    }
    clearInterval(i);
  }
}

var seconds = 5,
    i = setInterval(countDown, 2 * 420000);
    
asked by anonymous 07.05.2018 / 17:29

0 answers