Go here: http://www.infinite-scroll.com/ Play with the infinite scroll. Notice that you can\'t click a link and then hit \"back\". It has glitches when you do that.
So,
The only way to be able to handle the back button is to alter the location hash (the bit after the # symbol). Handling pressing of the back and forward buttons can be done in two ways:
which is unique to each section added, and change the location.hash to match it.setInterval
with a short time like 100ms to watch the location.hash for changes and go to the required part of the page. You have to do this because you can't actually detect when the back/forward buttons are clicked.This is an implementation of the second method to show you how it works. In this, each ajax request contains and
ajax-section-2
etc.
function addToBottom(htmlToAdd) {
$('#main-div').append(htmlToAdd);
window.location.hash = $('#main-div a[name^=ajax-section-]').last().attr('name');
}