Redirect with timer and localStorage

Asked

Viewed 58 times

0

I’m 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 will return to index and in case now has to stay in index, then a time counter will run again the code of redirect 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);
  • But what is the index page for?

  • the index has the site.. in case the test.html would be an advertisement. That will open every x time... if you stay at index.html in the case

  • What is the expected result of your code? What is it doing that needs to be done or shouldn’t?

  • It opens the test.html at set time but I would like to open it when it enters the site and dps always at set time, and in case open the first time not and then give a settimout q I am not able to do

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.