How to get previous page url using jquery

前端 未结 9 1242
独厮守ぢ
独厮守ぢ 2020-12-02 18:40

How to get the previous page url using jquery?

I am using the following code to get the current page location

$(document).ready(function() {
var path         


        
相关标签:
9条回答
  • 2020-12-02 18:45
    var from = document.referrer;
    console.log(from);
    

    document.referrer won't be always available.

    0 讨论(0)
  • 2020-12-02 18:50

    If you are using PHP, you can check previous url using php script rather than javascript. Here is the code:

    echo $_SERVER['HTTP_REFERER'];
    

    Hope it helps even out of relevance :)

    0 讨论(0)
  • 2020-12-02 18:55

    Use can use one of below this

    history.back();     // equivalent to clicking back button
    history.go(-1);     // equivalent to history.back();
    

    I am using as below for back button

    <a class="btn btn-info float-right" onclick="history.back();" >Back</a>
    
    0 讨论(0)
  • 2020-12-02 18:57

    Easy as pie.

    $(document).ready(function() {
       var referrer =  document.referrer;
    });
    

    Hope it helps. It is not always available though.

    0 讨论(0)
  • 2020-12-02 18:58

    Do you mean something like history.go(-1);? It will go back to the previous page.

    window.history on MDN

    0 讨论(0)
  • 2020-12-02 18:58

    We have document.referrer for this, but it is not on which we can relay. This could be saved, could be not

    $(document).ready(function() {
       var referrer =  document.referrer;
    });
    

    The better approach is to add a cookie to store the previous-url in the browser.

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