Loop over “history” in javascript?

北战南征 提交于 2019-11-28 03:03:52

问题


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


回答1:


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




回答2:


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).



来源:https://stackoverflow.com/questions/1946963/loop-over-history-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!