How can I design a function that will track the previous page a user has viewed. It will be should be designed to be called on each page.
I will be using a cookies for sure and also they should expire at the end of the visit.
How to achieve that ? I am new to JavaScript :(
How can I design a function that will track the previous page a user has viewed. It will be should be designed to be called on each page.
I will be using a cookies for sure and also they should expire at the end of the visit.
How to achieve that ? I am new to JavaScript :(
Share Improve this question asked Jun 8, 2012 at 9:11 Anuj KulkarniAnuj Kulkarni 2,1997 gold badges33 silver badges45 bronze badges 4- Not possible unless it is on the same domain. document.referrer may hold the previous page but also may not. You can set a cookie, but the user may e from a different page in the same session. Can you explain what you need to do rather than how you think you may need to do it? – mplungjan Commented Jun 8, 2012 at 9:15
- previous page of a particular website or last viewed page from his history??? – Sibu Commented Jun 8, 2012 at 9:21
- 1 Yes previous page of a particular website ... – Anuj Kulkarni Commented Jun 8, 2012 at 9:35
- 1 possible duplicate of How do you get the previous url in Javascript? – jwueller Commented Apr 6, 2013 at 14:34
2 Answers
Reset to default 2If you can explain why you need it, we may find a better solution.
You can use histroy.back() function, i think this would help you.
http://www.w3schools./jsref/tryit.asp?filename=tryjsref_his_back
Document referrer will do this, you can then choose to do what ever you want with this url.
document.referrer