How to fix the back button when user clicks a link

2019-04-16 10:37发布

I have infinite-scrolling pagination on a search result page using ajax.

How can I make it so that when a user clicks a link off-site and returns via the back button, the results are scrolled into the ajax-loaded portion of the page where they left?

2条回答
仙女界的扛把子
2楼-- · 2019-04-16 10:51

Check out unspace's writeup of their Pageless implementation. They use a special div which gets moved along with scroll events, and also they use a temporary cookie to store the position.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-04-16 10:54

Google for jQuery ajax history plugins. There are many.

also look up jQuery haschange plugin: http://benalman.com/projects/jquery-hashchange-plugin/

basically you append / update (possibly increment) a '#result-set=1' to the page's URL. Then using the haschange plugin for eg. you can trigger your own code, move back or forward to how much of the results were shown by pagination etc. When a user clicks the back button and comes back to your page, the on load firing of haschange should work if you've wired up your pagination to work of the '#...' in the URL

查看更多
登录 后发表回答