views:

284

answers:

4

Is there a way to loop over the "history" object in javascript to find a specific page in the history?

+6  A: 

Security reasons - no, you can not dump the history of the browser (with javascript)

I mean you can not do

for(i=0;i<window.history.length; i++)
{
      alert(window.history[i]);
}

However I don't have good explanation why history.go(n); is ok

Svetlozar Angelov
`history.go(n)` is ok because it doesn't give you any information about the users history... it only sends them back to that location.
TM
What about the properties current, next and previous ? can't they reveal the URLs ? Thanks
Mahesh Velaga
Can anyone please clarify my question ? Thanks!
Mahesh Velaga
No, those properties are no longer available to web scripting in any browser. `history.go()` isn't a security problem, but it's certainly a usability problem and should never be used.
bobince
@bobince Thanks for the clarification :)
Mahesh Velaga
+2  A: 

No, because it would you the ability to basically spy on the web history of anyone visiting your site (you could send this information to your server using Javascript).

You can redirect the client to particular pages in their history using the Javascript history object's back(), forward(), and go() methods. You just can't know where exactly you're redirecting them (except in the case of using go() to redirect to a URL instead of a history number).

Kaleb Brasee
A: 

You can put that link on the page and check to see if it is visited.

tgandrews
+1  A: 

Don't abuse this for evil, but you can use the CSS history hack.

zachleat
That... doesn't really do the same thing.
Shog9
It's a method to find if a certain URL is in a browser's history, so it certainly applies to the question.
zachleat