Monday, September 3, 2012

To get previous page URL using Javascript/JQuery


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

Plunker: http://embed.plnkr.co/F09nbn/preview

8 comments:

  1. this is redirecting to root path.

    ReplyDelete
    Replies
    1. I am not sure about the issue you facing. I have mentioned here to get the referrer property returns the URL of the document that loaded the current document. So, tell me how can i help?

      Delete
  2. Hi,
    I'm using above code with "alert(referrer)", but its not showing anything, means it returns nothig...

    ReplyDelete
  3. Created plunker use it http://embed.plnkr.co/F09nbn/preview

    ReplyDelete
  4. if i used referrer property, it'll go to the previous page but when i was press f5 key on the previous page it'll get null value from the referrer property so that i can not go to the previous page. How can i solve this issue? kindly help me.

    ReplyDelete
    Replies
    1. It is expected. You cannot override it. You should have your customized logic to keep track of your previous pages.

      Delete
  5. If i used mobile jquery then...?

    ReplyDelete