homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

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

5+ Year Member Top Contributors Of The Month

Msg#: 4606679 posted 5:14 am on Sep 2, 2013 (gmt 0)

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.



WebmasterWorld Senior Member 5+ Year Member

Msg#: 4606679 posted 6:35 pm on Sep 2, 2013 (gmt 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved