Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete browser history using jQuery

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.

like image 443
geo Avatar asked Apr 17 '09 17:04

geo


People also ask

How do I clear browsing data in JavaScript?

location. replace() it is used to clear the last entry in the history and replace it with the address of a new url. replace() removes the URL of the current document from the document history, meaning that it is not possible to use the "back" button to navigate back to the original document.


2 Answers

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.

like image 109
Ben Lowery Avatar answered Sep 18 '22 11:09

Ben Lowery


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.

like image 42
shreddd Avatar answered Sep 18 '22 11:09

shreddd