views:

37

answers:

4

Is there any way I can change the URL or add more history to the "back button" without having to refresh the entire page?

My application is AJAX based and I'd like to add some "undo" events to history so that the user can simply hit back and retain the old values.

What's possible today? I hear some of this may be in HTML5 but haven't checked whats supported in current browsers.

A: 

I think you can use window.location.hash to track the #part of the page, in your case, #state1, #state2 and so on.

window.location.hash = '#state' + (++ stateN) to set and stateN = parseInt(window.location.hash.match(/\d+$/)[0])

See http://stackoverflow.com/questions/680785/on-window-location-hash-change for more details about how to detect location hash changes.

SHiNKiROU
A: 

You could use 301 redirection. Personally, I would use cookies on the client side, or sessions in your back end, to store the breadcrumbs. Storing state information in the URL is a bad idea for AJAX applications, because people might return to a url that the server side is not in the right state to respond to.

Another option would be to provide your own Back button that knows which page to go back to.

dj_segfault
A: 

The answer for this question will be more or less the same as my answers for these questions:

In summary, two projects that you'll probably want to look at which explain the whole hashchange process and using it with ajax are:

  • jQuery History (using hashes to manage your pages state and bind to changes to update your page).

  • jQuery Ajaxy (ajax extension for jQuery History, to allow for complete ajax websites while being completely unobtrusive and gracefully degradable).

balupton
A: 

It is possible to use ASP.NET's built in Script Manager to update the browser's history. A full how-to to do this is located here:

http://www.asp.net/aspnet-in-net-35-sp1/videos/introduction-to-aspnet-ajax-history

MakerOfThings7