2

I saw the other questions/answers related to this issue, but I couldn't find anything that explains it clearly.

I want to know if there is any JavaScript code that refreshes the page when user presses the back button. Like in Facebook or Gmail, when you perform a log-out then press the back button, nothing happens; the page gets refreshed.

I created a web project and when the user performed a log-out, then the session is terminated and it is redirected to the index page. But if the user wants he can go back through back button and see the information again.

Noah Martin
  • 1,449
  • 7
  • 29
  • 65
  • This link is not about javascript, jsp, java. Just general talk – Noah Martin Jan 27 '13 at 23:56
  • 1
    you're right, im sorry for starting the close vote train :( – goat Jan 27 '13 at 23:58
  • 1
    At the other side it does not respond to my question about something like facebook or gmail – Noah Martin Jan 27 '13 at 23:58
  • Thank you rambo, I really searched a lot for a solution for this but no one till now has been clear – Noah Martin Jan 28 '13 at 00:00
  • I did a general search on something among the same lines of your question and so far all of them are very clear: you don't use javascript to prevent the user from going back, you change your response's caching policy so they are **alwyas** requested from the server. – asermax Jan 28 '13 at 00:01
  • can you please tell me how to do that? or if you may please post the link – Noah Martin Jan 28 '13 at 00:03
  • @AlbanoVito, I don't have a full answer for you, but I think you could force some js to be executed by studying [this page](http://stackoverflow.com/questions/2638292/after-travelling-back-in-firefox-history-javascript-wont-run) and the bfcache behavior. You could use that to re-request the content from the server, and let cookies or whatever be the deciding factor of whether content gets served. – goat Jan 28 '13 at 00:05
  • It is not what I am looking for, thank you for your answer anyway. I will search on my own and I will respond if I will find something – Noah Martin Jan 28 '13 at 00:10

1 Answers1

2

If you tell the browser to not cache the page it will request it again when they press the back button.

Samuel Edwin Ward
  • 6,135
  • 3
  • 28
  • 59
  • I have to tell the browser no to cache all the pages within the website or is there any way to tell the browser to delete the cached content? – Noah Martin Jan 28 '13 at 00:01
  • @AlbanoVito, I don't know of a way to delete the browser's cache. – Samuel Edwin Ward Jan 28 '13 at 00:04
  • I do not want to bother you but please explain a little more if you can. So it is the first choice? I have to tell the browser not to cache all the pages? – Noah Martin Jan 28 '13 at 00:06
  • @AlbanoVito, yes. There's a *lot* of discussion about that in [another question](http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers). – Samuel Edwin Ward Jan 28 '13 at 00:11
  • That question was for 2008 and maybe it worked back then but I just tested in Firefox 18, IE 8 and Chrome 24 and I was able to go back and see my pages again after making the changes in my code – Noah Martin Jan 28 '13 at 00:23
  • @AlbanoVito, I would guess that either the page was already in your cache or you chose the wrong answer. – Samuel Edwin Ward Jan 28 '13 at 02:53