Hey I'm calling history.back() on the on-click of a 'back' button in a rails app. But nothing happens. There is history in the browser -- pressing the browser's back button takes me back to the correct page.
Any ideas how to debug this?
I tried this in FF and Safari.
Ok I played around some more and this works:
Originally, the code was:
<a href='#' onclick='history.back();'>
What's the difference? (Note that this used to work before, something has changed which makes the latter link not work)
have you tried adding return false? So:
<a href='#' onclick='history.go(-1);return false;'>
If you use link_to_function it will automatically add return false to the end.
<%= link_to_function "Go back", "history.back()" %>
I'd recommend using <%= link_to :back %>. Read more here: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M002142