Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Michael Rockett
40,365 PointsHow can I use make the browser back button refresh the page?
Hi,
I'm trying to use javascript/jquery to cause the browser back button to refresh the previous page or redirect to another page. This is because I have a form that I want to be cleared when a user goes back.
Thanks, Mike

Michael Rockett
40,365 PointsHi, thanks for your answer but it still doesn't seem to do it for some reason.
2 Answers

Cena Mayo
55,236 PointsHi Michael,
You might want to take a look at this discussion on StackOverflow
I've spent some time this morning researching this question and it looks like it's more complicated than it appears, so the above link may not be exactly what you need, but hopefully will help you get on the right track to a solution.

Michael Rockett
40,365 PointsThanks, I haven't solved it yet but I think this has put me in the right direction

Michael Rockett
40,365 PointsI have found a solution. I've got the page to clear all the form fields when the back button is pressed. The code is below for anyone who has the same problem.
$(window).bind("pageshow", function() { // update hidden input field $('#formid')[0].reset(); });
Jacobus Hindson
14,429 PointsJacobus Hindson
14,429 Points<body onload="document.refresh();">
This would enforce the page to reload anytime it is hit. Give it a try.