Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting previous url

Status
Not open for further replies.

jkris

Programmer
Jun 12, 2003
13
0
0
IN
how do i get the url of the page from which i got into the current page in javascript?

thanks
 
<script>
if (document.referrer&&document.referrer!=&quot;&quot;)
document.write('Thanks for visiting this site from '+document.referrer+'<BR>');
</script>

Note this only works when posted on a web server.

Hope it helps
 
thanx mit, but i need a code which wud work xactly as &quot;javascript:history.back()&quot;, if i use document.referrer n i goo from page 1 to 2 to 3, then clicking the back button of 3 takes me to 2 n clicking back of 2 again takes me to 3 instead of 1. &quot;javascript:history.back()&quot; does the trick but i need an alternative, is there any code to get the url of &quot;javascript:history.back()&quot;?


regards,
JK
 
document.referrer takes you to the previous page if you go 1 -> 2 -> 3 -> 2

Then the previous page is 3

You cannot access the array of urls in the history directly only via back() and forward().

 
You could set a cookie when page 3 loads and read the cookie when page 1 loads. If page 1 sees the cookie exists, it redirects to page 2.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top