Handle JavaScript window.history

4

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

    
asked by anonymous 17.08.2016 / 20:01

2 answers

7

This is not possible.

There are security issues involved in the fact that every website you visit \ visited could be seen by all the other sites you've been to.

An alteration to get around this, as long as it is on your own site would use session management techniques, they are:

  • Cookie Data
  • URL Parameters
  • Server-side session information
17.08.2016 / 20:17
3

With normal navigations, however, it is not 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 combine with sessionStorage and use something with var currentState = history.state; to get the state.

And to detect the changes use this event:

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

I have not found anything ready, not in Github, but I will keep looking, if I do not do anything I will try to create a basic functional example (of course the application of this will depend very much on how your system is)

    
17.08.2016 / 20:25