Prevent browser from binding to previous scroll position when pressing return button

I need the browser to not snap to the previous scroll position when the user clicks the back button as follows:

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

after clicking this button, the browser will return to the previous scroll position on this page. I want to stop this behavior and just load the top of the page.

Hope someone knows the right solution.

-exemple -

open the scroll page down, go to a new page and click the "Back" button, the page will automatically scroll to the place you scroll before!

+6
source share
3 answers

I am sure that the behavior you describe is best classified as one of those things that are considered user preferences. (One of those things that you are not going to interfere with)

@mrtsherman came up with a hack / workaround for this , but if it doesn’t seriously compromise the usability of Webapp, I think you should let the browser behave the way the user would normally expect them to behave (and scroll to the position where they were when they left the page). Be sure to save mrtsherman for his sweet js nugget if you use it.

+1
source

I have the same problem and I have not found the right solution yet,
but I can give you a very good workaround for this problem.

Just scroll up to to load the next page.
When the user returns, the browser will move up.

Example:

First page:
<a href="page2.htm" onclick="window.scrollTo(0, 0);">Next</a>

Second page:
<a href="page1.htm" onclick="history.go(-1); return false;">Back</a>

Please note that href="page1.htm" only loads if the user chooses to open in a new window / tab

Sorry my english. Hope this helps.

0
source

I have found the best solution!

Put the following code on each page:

 <script> setTimeout('window.scrollTo(0, 0);', 1); </script> 
-4
source

Source: https://habr.com/ru/post/920630/


All Articles