javascript - Maintaining Scroll Position With Back Button and Ajax Dom Manipulation -


i loading results in ajax infinite scroll, however, when click item in list , navigate away page, click button, @ top of list.

i can't figure out how make user return position left off.

see site working on: https://www.studenthouses.com/search/manchester/

scroll down few times, click property, click , see mean.

i can't remember result position , load them in because take long, need browser remember dom when comes page, or cache how.

is there solution this?

many thanks

sure there , it's piece of cake. well, it's cookie, :)

you don't need solve problem.

first, cookie here: cookie api

second, you'll have encode data in cookie somehow. if have multiple pages one, you'll have separate them somehow or use key-value pair , store this:

manchester=3522 

whenever enter page, load cookie, wait page unrolled (you use ajax or similar, you'll have wait page being unrolled, window.onload won't do).

if there no cookie, skip step:

  • scroll page down offset have loaded cookie: scrollto

next, whenever page scrolled, modify cookie. avoid thrashing you'll want in polling manner. use setinterval() @ maybe 500 milliseconds , check if user changed scrolling position. if did, save cookie new value.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -