问题
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