views:

43

answers:

2

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?

+1  A: 

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

Moin Zaman
Thanks, is there a way to do it without messing with the hash?
Rudy
among the jquery history plugins there are some that work using iframes. i think one of them doesn't mess with the '#'
Moin Zaman
Thanks, I'll have a look.
Rudy
Ah, looks like the trick is to save the hash in the iframe itself. Seems to work well enough for me.
Rudy
Hmm, does actually seem to work in ie, unless there is some other way to get the iframe hash...
Rudy
No, none of these approaches work if you go off-page unfortunately, they are designed for within-page history. I'll have to keep looking.
Rudy
yup, cookies could be a way to do it. But try the haschange plugin a little differently. Why can't you mess with the # in the URL? I'm currently using haschange to determine which accordion to keep open after going off-page and returning with the back button. Have a look here: https://dl.dropbox.com/u/2556919/me/index.html Go and open a few of the sections, click away on the portfolio links or browse off the page and come back and you'll see how the haschange is working. The code is in the source at the bottom.
Moin Zaman
haschange would work if I could have hashes in the url. But I can't have a link available which would go to e.g. 1000 results down, it should just for the back-button.
Rudy
A: 

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.

Anthony Mills