Reputation: 33684
I wanted to know if it's possible to have a for loop over the stack of the URL in the history API.. so basically I wanted to pop up the history URL stack until I reached URL X. How can I do that? Is it possible?
Upvotes: 3
Views: 1302
Reputation: 944568
You can keep calling history.back()
until location.href
is the value you want.
This will only work if going back in the history keeps you on the same page (e.g. because you are going back through history objects that you added with pushState
), otherwise your JS will stop running.
Upvotes: 2
Reputation: 5921
It's not possible. Getting any URL data from the history object would be a huge privacy concern as anyone could read your browsing history.
Upvotes: 0