I want to get url of previous page. I found a lot of answers but I couldn't find anything which works with back button of browser. I used document.referrer but it also doesn't work for back button. Can anyone help me??
Asked
Active
Viewed 1.4k times
7
-
See the history API. – Barmar Jan 19 '15 at 12:02
-
i have same issue, i used local storage (or you can use cookie as well) to store previous url. localStorage.setItem("previourUrl", window.location.href); and get url of previous page by localStorage.getItem("previourUrl"); Hope it will help someone :) – Devesh Chauhan Nov 22 '16 at 11:49
2 Answers
4
Use the following in javascript snipet
document.referrer;
if you are implementing back button use this
<a href="javascript: history.go(-1)">Back</a>

Shashidhar Patil
- 45
- 6
-
Back This link will redirect me to previous page whereas I need url of previuos page when browser back button is clicked. – ishakya Jan 21 '15 at 05:35
-2
you can use document.referrer
.
in your javascript file, just simply add
window.location = document.referrer;

Alongkorn
- 3,968
- 1
- 24
- 41