1

I've got a site that allows you to search for images. I wrote a simple script for infinite scrolling, but had an issue with using the browser's back button. Basically, if you scrolled down a lot and infinite scrolling was loading new "pages" of images, then you clicked on one of the images, then hit back to go back to the search results, you'd be back at the 1st page of results. To get back to where you were, you'd have to scroll through all of those "pages" you've already scrolled through.

I attempted to solve this by updating the browser history when you click on an image. When you click on an image, it sets the history to search/page_num#image_id. That way when you hit back, it takes you right to the page you were on and should scroll to the image.

The URL gets properly set in browser history. And if I manually type in that URL, the browser loads the right page number and scrolls to the right image. But when I try to use it in a real life scenario (searching, scrolling, clicking an image, hitting back to get back to the results), the browser doesn't scroll to the image anchor.

Anyone know how I can fix this? Thanks!

user2874270
  • 1,190
  • 1
  • 17
  • 29

0 Answers0