Saving scroll position when coming back

466 views Asked by At

I am trying to save the scroll position of a page, when we go from that page (a product list) to a product, and then back to the product list. The only scenario this scenario should occur is when going from prodlist to prod to prodlist (pressing back).

My first thought was to check the URL from history in javascript, but history.back is not read, it's only action.

2

There are 2 answers

0
Rasmus Edvardsen On

Okay, we've found a solution. Apparently we already had an implementation of breadcrumb navigation, so I simply just pulled the middle element (we have 3), to check where the user was before the product. If the back button is pressed, we have our filters preserved.

Therefore, the only thing here was to query for products on the productlist equal to the middle href in the breadcrumb, and scrollTop to the product.offset().top, and bam.

Have a good day whomever reads this.

2
Hossein Daneshfar On

you can use jquery and call Position method or. Offset method on the window. And get x and y from top and left. Then store the x, y into a localStorage. Localstorage is for HTML5 very easy. And when user back to old page, read x, y from. Localstorage Example : localStorage. SetItem(name , value); LocalStorage. GetItem(name );