I'm working with JS, JQuery, & PHP and trying to do is solve an infinite scroll problem. The problem is that if you scroll for a long way down the page and it loads more pages with ajax, then click a link to go to a new page, how do you automatically go to that same location in the old page when using the browser back button on the new page?
. New pages are loaded on scroll using ajax.
The solution I've come up with to my question is to store each page along with relevant data prior to navigating away from the page.
The following information is required to maintain scroll position:
When the next page is loaded, the previous information can be stored using local storage. When going back to the previous page, look up the PageID in storage. If it exists, then grab the X or Y coordinate and move page to the position. This takes some strategic thinking because if the page is a lazy-loaded (infinite scroll) type of page or feed, you'll need to have the data already OR be prepared to look up the data based on the position of the page.