How to view the contents of history object in javascript?

对着背影说爱祢 提交于 2019-12-12 02:39:39

问题


The history object contains the URLs visited by the user (within a browser window). How do I view the visited URLs? I tried consoling the object and checked through all the fields, couldn't find the required data. history.back() will load the previous, but I just want to know the previous URL.


回答1:


You cannot do this. It's made for security reasons. However you can view the last one (page which you came from) by checking document.referrer. See more here




回答2:


Maybe you can have some kind of solution saving the document.referrer using localStorage each time you need.



来源:https://stackoverflow.com/questions/33368048/how-to-view-the-contents-of-history-object-in-javascript

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