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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing referer

Status
Not open for further replies.

electricphp

Programmer
Feb 20, 2008
71
US
ok, I'm not sure if I should be posting this here or in the asp forum but here it goes.

What I'm trying to do is pass the referrer of an html page to an asp page for processing. The way I'm doing this is:

Code:
function getref(){

if (document.referrer&&document.referrer!="")
  document.write('<img src="[URL unfurl="true"]http://www.designerwebs.us/access-log.asp?pg=contact.html?ref="'+document.referrer+'>');}[/URL]

<img src="[URL unfurl="true"]http://www.designerwebs.us/access-log.asp?pg=contact.html&ref=javascript:getref()"[/URL] border="0">

There are 2 problems. the first is that the function is not invoked, it simply passes javascript:getref() instead of the output of the function.

The second problem is that even if it passed the actual URL, the characters in the url such as & ? etc., would mess up the post variable. I would need the referring url to be passed in quotes or something.


On the asp page it simply gets inserted in the database as a post value.

I hope this makes sense
 
You can do it like this. (Why document.write seems to be used by so many so often?)

[1] script section
[tt]
<script type="text/javascript">
function getref(){
if (document.referrer&&document.referrer!="")
var obj=document.getElementById("imgid");
obj.src+="[red]&[/red]ref=" + encodeURIComponent(document.referrer);
}
}
window.onload=getref;
//other stuff
</script>
[/tt]
[2] Body section
[tt]
<img src="[ignore][/ignore]" border="0" alt="pic" />[/tt]
 
If you mean that referrer is to appear as the querystring of the request "pq" and not as an independent request "ref", it is this.
[tt]
function getref(){
if (document.referrer&&document.referrer!="")
var obj=document.getElementById("imgid");
obj.src+=encodeURIComponent("?ref=" + document.referrer);
}
}
[/tt]
But,... requesting a .htm with querystring? well, never heard of it.
 
referrer should appear as the querystring of the request "ref" so the code should be something like this:

Code:
<img id="imgid" src="[URL unfurl="true"]http://www.designerwebs.us/access-log.asp?pg=contact.html&ref=(javascript[/URL] function passes the referer here)" border="0" alt="pic" />
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top