Force a page refresh when page visited from back button

16,301

Solution 1

Set a cookie on page 2.

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

Solution 2

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.

Share:
16,301
Mark_54
Author by

Mark_54

Updated on June 16, 2022

Comments

  • Mark_54
    Mark_54 almost 2 years

    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?

  • Mark_54
    Mark_54 over 12 years
    Diodeus, that was my intended approach but I though there might be a better way... Thanks for replying.
  • Mark_54
    Mark_54 over 12 years
    Ascalonian, I tried this to occur on the body onload but it doesn't seem to recognised the referrer if it's been referred via the back button. Any ideas?
  • Diodeus - James MacFarlane
    Diodeus - James MacFarlane about 11 years
    There are many examples of reading and setting cookies on this site already.