1

When I push the back button my browser seems to load the page from some kind of cache and seems to re-fill some of the input fields with the values they had before I moved to another page by clicking a link. However, the site's state seems to be messed up because it has a bunch of "impossible" bugs that only appear when it's re-visited via pressing the back button.

How can I find out if this happened and then reload the page or prevent this from happening altogether? (Like forcing a reload each time the browser displays the page anew?)

douira
  • 506
  • 1
  • 6
  • 22

1 Answers1

1

you can check to see if the page was accessed via the browser history, like this

if (!!window.performance && window.performance.navigation.type === 2) {
            // value 2 means "The page was accessed by navigating into the history"
            console.log('Reloading');
            window.location.reload(); // reload whole page

        }
CumminUp07
  • 1,936
  • 1
  • 8
  • 21