最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

cookies - How to get previous page URL in javascript? - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 2

If 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
发布评论

评论列表(0)

  1. 暂无评论