How to get the previous URL in JavaScript?

后端 未结 7 774
野趣味
野趣味 2020-11-22 06:05

Is there any way to get the previous URL in JavaScript? Something like this:

alert(\"previous url is: \" + window.history.previous.href);

相关标签:
7条回答
  • 2020-11-22 06:37

    If you want to go to the previous page without knowing the url, you could use the new History api.

    history.back(); //Go to the previous page
    history.forward(); //Go to the next page in the stack
    history.go(index); //Where index could be 1, -1, 56, etc.
    

    But you can't manipulate the content of the history stack on browser that doesn't support the HTML5 History API

    For more information see the doc

    0 讨论(0)
提交回复
热议问题