Manipulating Javascript window.history

Asked

Viewed 176 times

4

Is there any way to list the URL’s of window.history? If I want to use window.history.go(-2), has how to know which URL this -2 will return?

2 answers

7


That is not possible.

There are security issues involved by the fact that every website you visit could be viewed by all the other websites you have been on.

An alterative to circumvent this, as long as it is on its own site would use session management techniques, are they:

  • Data of Cookies
  • URL parameters
  • Server-side Session Information

3

With normal browsing not, however it is possible to "create/manipulate" the Urls using, the navigation in this case would be by ajax:

var estadoDoObj = { foo: "bar" }; //Estado "atual"

history.pushState(estadoDoObj, "page 2", "bar.html");

and could match with sessionStorage and wear something with var currentState = history.state; to get the status.

And to detect the changes use this event:

window.addEventListener("popstate", function(event) {
  //...
});

I couldn’t find anything ready, even on Github, but I’ll keep looking, if I don’t get anything I’ll try to create a basic functional example (of course the application of this will depend a lot on what your system looks like)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.