开发者

How to get parent url

For instance my current url is

http:/开发者_JS百科/www.sample.com/check/?code=1

Web page under this url contains a link

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

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

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

Thanks in advance...


<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.com/check/?code=2&scr=http://foo.com/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.org/en/document.referrer for info about the referrer.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜