views:

2668

answers:

2

I have an ajax application that is based on jQuery. I enabled browser history using jQuery history plugin. But we find out that the application generated too much history.

Especially, we provide an in-page "ajax-back" button that enable the page to return to previous ajax state. When the in-page "ajax-back" button was pressed, we want it to act like the broswer back button, by moving the current index of the history, or removing the latest history record, instand of inserting a new history record.

So, I would like to ask, is it possible to remove the latest browser record from javascript? or is it possible to modify the current index of the browser history list?

Examples that are based on jQuery history plugin will be very appreciated.

+3  A: 

Most likely you can't easily do what you're attempting. There is window.location.replace, which goes to a new URL and removes the current page from the history, but that's for full page navigations and will almost certainly break jQuery's way of faking history.

It is possible to change where in the history stack you are, using window.history.go(), which takes an integer offset into history and navigates to the relevant entry. It doesn't modify the stack at all, it just puts you in a new place. There are also back() and forward() functions which just call go with -1 and 1 respectively. This is probably what you're looking for, though it won't modify the stack, just move you around in it.

Ideally, you'd find a plugin for jQuery that doesn't maintain history the way jQuery.history does, but instead offers an onhashchange abstraction, and your library would just react to hash changes. That way, the browser is in charge of the history stack and you won't run into a lot of the crazy issues that dog ajaxian history libraries.

Ben Lowery
+1. Ersatz navigation is a usability nightmare. Use the real back/forward buttons.
bobince
A: 

browser history is typically accessible in a very limited way through javascript (to prevent sites from snooping/accessing that information). short answer - what you are trying to do is not available to you through jquery, as far as I know.

shreddd