Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force a page refresh when page visited from back button

How can I force a page refresh of page 1 when a user returns to it from page 2 by pressing the back button? Are there vbscript or javascript approaches or is it down to set the 'no cache' somehow?

like image 874
Mark_54 Avatar asked Feb 09 '12 17:02

Mark_54


People also ask

How do you refresh a page when a button is clicked?

reload() method gives the same result as pressing the reload button on your browser. This method reloads the page from directly the browser's cache by default.

How do I trigger a refresh page?

reload() method reloads the current web page. The method gives the exact same result as pressing the RELOAD button in your browser. The JavaScript reload page method loads the page from the cache by default. If the forceGet property is set to true, the page is reloaded from the server.

How do I force a HTML page to refresh?

In most web browsers you can force a one-time page load from the server by holding down the shift key while clicking on the Reload or Refresh button.


2 Answers

Set a cookie on page 2.

If the cookie is detected on page 1, reload the page.

like image 56
Diodeus - James MacFarlane Avatar answered Dec 02 '22 17:12

Diodeus - James MacFarlane


What about doing something like this?

<script>
    if   (document.referrer == "http://www.page2.html") 
          window.location.reload(); 
    }
</script>

Just throw that at the top of your page 1 and this should work.

Update

I also found a solution on the Webdeveloper.com forums as well.

like image 20
Ascalonian Avatar answered Dec 02 '22 18:12

Ascalonian