javascript - How to get parent url - Stack Overflow

For instance my current url is?code=1Web page under this url contains a link <a href="?code=2

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745428364a4627281.html

相关推荐

  • javascript - How to get parent url - Stack Overflow

    For instance my current url is?code=1Web page under this url contains a link <a href="?code=2

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信