JavaScript document.referer

how to use in a URL Variable

Page 1 of 1

6 Replies - 14593 Views - Last Post: 03 June 2009 - 05:41 AM

#1 supersssweety  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 22
  • View blog
  • Posts: 373
  • Joined: 16-March 07

JavaScript document.referer

Posted 07 September 2007 - 08:02 AM

I wanna say something like http://blahblahblah....ocument.referer

but it isn't that easy, what syntax do I need for this to work?
Is This A Good Question/Topic? 0
  • +

Replies To: JavaScript document.referer

#2 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: JavaScript document.referer

Posted 07 September 2007 - 08:16 AM

Variable declaration and assignment? Javascript and DOM principles?

I think you'll need to get a handle on those before anything else.
Was This Post Helpful? 0
  • +
  • -

#3 supersssweety  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 22
  • View blog
  • Posts: 373
  • Joined: 16-March 07

Re: JavaScript document.referer

Posted 07 September 2007 - 08:19 AM

View Posthotsnoj, on 7 Sep, 2007 - 08:16 AM, said:

Variable declaration and assignment? Javascript and DOM principles?

I think you'll need to get a handle on those before anything else.



mmmk so could you point me in the right direction on that and using url variables?
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: JavaScript document.referer

Posted 07 September 2007 - 08:40 AM

The easiest way to accomplish this (and trust me Im going to get "screamed" at for this LOL) is to write a small function to do this for you, such as (Remember this is only a sample and some tweaking will be needed to make it work)

function AppendReferrer(link)
{
	var ref = document.referrer;
	var new_link = link+'?r='+ref;
	document.write(new_link);
}



Then in your href tag call that function

<a href="AppendReferrer('http://www.somesite.com');">Some Link</a>



For future reference W3Schools.Com is a good place to learn good Javascript.

Hope this helps :)
Was This Post Helpful? 0
  • +
  • -

#5 supersssweety  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 22
  • View blog
  • Posts: 373
  • Joined: 16-March 07

Re: JavaScript document.referer

Posted 07 September 2007 - 08:48 AM

View PostPsychoCoder, on 7 Sep, 2007 - 08:40 AM, said:

The easiest way to accomplish this (and trust me Im going to get "screamed" at for this LOL) is to write a small function to do this for you, such as (Remember this is only a sample and some tweaking will be needed to make it work)

function AppendReferrer(link)
{
	var ref = document.referrer;
	var new_link = link+'?r='+ref;
	document.write(new_link);
}



Then in your href tag call that function

<a href="AppendReferrer('http://www.somesite.com');">Some Link</a>



For future reference W3Schools.Com is a good place to learn good Javascript.

Hope this helps :)


Wow thanks, I will let you know how it goes, I have always used other scripts that I find and tweak them, tweaking is something I can do, not a javascript guru, and with so many scripts availiable, I don't see why I should have to be, no use in reinventing the wheel right, and I have been racking my brain all morning trying to find out how to use javascript url variables...geez it's not as easy as any other scripting language, I knew I would have to make a function -- I didn't know I would have to build the url together like a puzzle though, but I just couldn't find anything on javascript and URL variables. I will work with this THANK YOU so much.
Was This Post Helpful? 0
  • +
  • -

#6 supersssweety  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 22
  • View blog
  • Posts: 373
  • Joined: 16-March 07

Re: JavaScript document.referer

Posted 07 September 2007 - 11:44 AM

Well I got it figured out, so I decided to just go ahead and build the whole thing in the function because I played with it a lot trying to get it to work, and it finally worked this way, so I just left it:

<script type="text/javascript" language="javascript">
function AppendReferer(link)
{
	var ref = document.referrer;
	var new_link = '<img src="'+link+'&r='+escape(ref)+'"'+'border="0" height="0" width="0">';
	document.write(new_link);
}
</script>
<script type="text/javascript">
AppendReferer('http://www.xxxxxxxx.com/w.cfm?l=00');
</script>



so what is up with ColdFusion calling it CGI.HTTP_REFERER with one R and javascript spells it right with two r's?

starngeness all around

but that is what the hold up was, plus I had to figure out what I needed to put around the calling of Appendreferer.
Thank you PhsycoCoder your are my hero! hahaha hope you didn't get into to much trouble

<3

This post has been edited by supersssweety: 07 September 2007 - 11:46 AM

Was This Post Helpful? 0
  • +
  • -

#7 dododidi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-June 09

Re: JavaScript document.referer

Posted 03 June 2009 - 05:41 AM

View Postsupersssweety, on 7 Sep, 2007 - 10:44 AM, said:

Well I got it figured out, so I decided to just go ahead and build the whole thing in the function because I played with it a lot trying to get it to work, and it finally worked this way, so I just left it:

<script type="text/javascript" language="javascript">
function AppendReferer(link)
{
	var ref = document.referrer;
	var new_link = '<img src="'+link+'&r='+escape(ref)+'"'+'border="0" height="0" width="0">';
	document.write(new_link);
}
</script>
<script type="text/javascript">
AppendReferer('http://www.xxxxxxxx.com/w.cfm?l=00');
</script>



so what is up with ColdFusion calling it CGI.HTTP_REFERER with one R and javascript spells it right with two r's?

starngeness all around

but that is what the hold up was, plus I had to figure out what I needed to put around the calling of Appendreferer.
Thank you PhsycoCoder your are my hero! hahaha hope you didn't get into to much trouble

<3


Hello folks,

I have just tried the above with a .txt page:

AppendReferer('http://www.nigels.de/w.txt');
.

well obviously I dont understand much about JS, but is there any chance of quick explanation? as far as I know, a .cfm file is simply another format for .txt files, or not?

any help would be great
thx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1