0

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.

  • Are you using some framework for front end development? Like Angular or Vue. – Aosis Sep 14 '17 at 07:35
  • You can use anchor id's (i.e.
    and access that page part with http://someurl.com#position, this way you can have link straight to the part of page you want. Keep in mind id's are unique per element on page. You could also implement some smoothscroll to make it better.
    – pegla Sep 14 '17 at 07:45

2 Answers2

0

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 );

  • Okay that's really interesting. The only problem is that there are multiple ways to get to the product, and only from the productlist should this occur. Any idea how I can distinguish between the pages back from product? – Rasmus Edvardsen Sep 14 '17 at 08:14
  • If you are using some routing framework, you should be getting routeChangeStart event inside which you can get the route to which the app if going to. You can intercept a specific route there. – Aosis Sep 14 '17 at 08:33
0

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.