admin管理员组

文章数量:1303414

Here is 1.html

<!DOCTYPE html>
<html>
  1
  <script>
    let time = 0;
    setInterval(() => {
      if (time === 500) location.href = '/2.html';
      time++;
    }, 1);
  </script>
</html>

And here is 2.html

<!DOCTYPE html>
<html>
  <body>
    2
  </body>
</html>

If access to 1.html, according to setInterval(), the page will be moved to 2.html 0.5 seconds later by location.href new value.
However, it is not possible to go back to 1.html using back button on a browser.
I've heard that the reason of it is location.href was executed not by user events (like clicking) but by force caused by my code.
I want to know how to make it work!

I tried history.pushState method to make the browser know that there is one more page you(browser) should add to the stack.
It worked if I go back to previous page by history.back().
However, it still didn't work if I tried to go back to previous page by pressing go back button on a browser.

本文标签: