3

How to get the previous page URL? can we get this using the window.history ?

Note - We only need that URL and no need to perform any redirection.

Shubham
  • 1,163
  • 2
  • 12
  • 36

1 Answers1

3

I am using document.referrer, it will return the previous URL you have visited

EDIT: I also found this code snippet, where you store the previous URL using cookies.

$.cookie("previousUrl", window.location.href, {path:"/"});

You can assign the cookie in a variable to retrieve its value or something like that

  • Thanks for your kind input and I really appreciate this. But No, It is giving the incorrect result. I've already tried this but in some cases, it not works. Is there any other way to do this? – Shubham Feb 27 '18 at 07:18
  • What do you mean by `incorrect` results? What is the expected result and what are you getting? Give examples of what you've tried. – Deepak Kamat Feb 27 '18 at 07:20
  • @JeremiahCabigting appreciate you helping but the OP hasn't made clear what doesn't work, if they have a somewhat different system they should specify it in their post, but no code snippet have been given at all. – Deepak Kamat Feb 27 '18 at 07:26
  • @DeepakKamatIt's just a small issue and you thought that I should have given a code snippet & screencast video for this? I don't want to spend my time on this activities. That's the reason why I didn't use the StackOverflow frequently. The guys here are very rude even they don't know about the sense of talking professionally. – Shubham Feb 27 '18 at 07:32