Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent browser from snapping to previous scroll position when pushing back button

I need to prevent browser from snapping to previous scroll position when the user pushed a back button like this:

<a href="javascript:history.go(-1)"
      onClick="javascript:history.go(-1)" title="< GO BACK"></a>

after pushing that button the browser will return to the previous scroll position on this page i want to stop that behavior and just load the top of the page.

Hope someone know a proper solution.

-exemple-

open a page scroll down go to a new page and hit the back button the page will auto scroll down to the place you scrolled before!

like image 226
phj Avatar asked Jul 16 '12 20:07

phj


1 Answers

I'm fairly certain the behavior you're describing is is best classified as one of those things considered to be a user preference. (One of those things that you're not meant to tamper with)

@mrtsherman came up with a hack/workaround for this, but unless it's seriously breaking your webapp's usability, I think you should let the browser behave as the user would normally expect it to behave (and scroll to the position they were in when they left the page). Be sure to upvote mrtsherman for his sweet nugget of js if you use it.

like image 113
MicronXD Avatar answered Oct 13 '22 02:10

MicronXD