Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

AJAX back button "snapshot" when returning from a different page

5:14 am on Sep 2, 2013 (gmt 0)

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
votes: 1

I use AJAX to load a page with a list of links. If the user clicks on one of the links they may eventually press their browser's back button and return to the list. Right now if they press the back button the first page returns back to its empty state, and AJAX will have to reload the list again.

Is there any way to create a "snapshot" of the page when the user clicks away and return to that point when a user clicks their back button?

I keep reading how url hashs might work, but it seems like the user never really leave the first page whereas my users are actually returning from a competently different page.
6:35 pm on Sept 2, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Dec 13, 2009
votes: 0

Well, doing this:

window.location.href = window.location.pathname + window.location.search + '#some_identifier';

Will add a record to the user's browser history without reloading the page.

Unfortunately, the browser doesn't send the anchor part of the URL with a HTTP request, so server side languages can't pick up on it. It's really just used so that AJAX driven sites can have specific parts of the site bookmarked by the user

(check window.location.hash - fire AJAX event tied to that anchor).

If you want to have URLs changing with an AJAX driven site that the server side can pick up on, you'll need to look into the HTML5 history API - I'm not aware of another way to do it.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members