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

javascript - How to get parent url - Stack Overflow

programmeradmin3浏览0评论

For instance my current url is

/?code=1

Web page under this url contains a link

<a href="/?code=2">Code2</a>

When this link is clicked it takes to /?code=2

Question: Under the web page displayed under /?code=2 i have to fetch the url from which this page had came from. How to do this.

Thanks in advance...

For instance my current url is

http://www.sample./check/?code=1

Web page under this url contains a link

<a href="http://www.sample./check/?code=2">Code2</a>

When this link is clicked it takes to http://www.sample./check/?code=2

Question: Under the web page displayed under http://www.sample./check/?code=2 i have to fetch the url from which this page had came from. How to do this.

Thanks in advance...

Share Improve this question asked Jul 13, 2011 at 6:29 Mohan RamMohan Ram 8,46325 gold badges85 silver badges131 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4
<script type="text/javascript">
alert(document.referrer);
</script>

If you control the original page, then you could put a source in the URL like this:

<a href="http://www.sample./check/?code=2&scr=http://foo./xxxx">Code2</a>

and you could parse that out of the URL in the 2nd page.

Or you can look at document.referrer in the 2nd page and see if it contains the value you want. See https://developer.mozilla/en/document.referrer for info about the referrer.

Information here: http://en.wikipedia/wiki/HTTP_referrer

发布评论

评论列表(0)

  1. 暂无评论