0

I need to check in a rails controller whether the user used the back button to come back to the page. Is there a specific method for this?

Splashlin
  • 7,225
  • 12
  • 46
  • 50
  • 1
    Most browsers don't fire a request at all when you hit the back button. They just take the page from cache. So it looks like you need to be looking at a way of doing this in Javascript? – Stéphan Kochen Jan 28 '10 at 08:06

1 Answers1

1

Telling that a user used the back button is very hard (maybe impossible?) for the reason Shtééf commented already.

But, you can make sure the page is fetched again from your webserver (instead of grabbed from the local cache), by sending some custom headers with it telling that the page should not be cached. More information on these headers can be found on Best way to disable client caching, Why both no-cache and no-store should be used in HTTP response? or take a look at these questions.

If you keep track on which page(s) the user has been you can see whether s/he returned to the previous page, which might indicate that the back button was used.

Community
  • 1
  • 1
Veger
  • 37,240
  • 11
  • 105
  • 116