Search code examples
javascriptbrowser-history

How to view the contents of history object in javascript?


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.


Solution

  • 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