Is it possible to take a user back to the area of a page where they scrolled down to when pressing the back button in a browser?
Hi hannahklewin,
Normally this is taken care of by the browser, but in the case of a Wix website the scroll position is reset after a couple of seconds (after loading of the page finished).
I think what you’re trying to achieve might in theory be possible, but very complex and probably slowing things down badly:
- Upon scrolling or leaving the page, trigger a function that retrieves the current scroll position
- You can retrieve the current scroll position using the wix-window getBoundingRect function (see wix-window documentation)
- Assign the output of windowSizeInfo.scroll.y to a variable
- Retrieve the ID of the current page using $w(“PageName”).id
- Store the scrollposition and page ID in your browser’s local or session storage (see wix-storage documentation)
- Upon entering a page, retrieve the stored scroll position of the current page ID
- Restore this scroll position using the scrollTo function (see wix-window documentation)
The problem with this approach is that (as far as I’m aware of) there is no easy way to detect a scrolling-, page enter- and page leave event in Wix Code. There used to be one called $w.ScrollEvent, but it no longer works since mid 2016.
Good luck! Michiel
Hi Michiel -thank you for explaining. Can I check that I understand correctly. The issue is that Wix resets after leaving the page so it automatically goes back to the top of any page when you use the back button? It does sound like the fix would be very complicated and beyond my pay grade! Thanks Hannah
@hannahklewin Hi Hannah, did you find any solutions to your issue? i’m having the same problem