Possible to get HTTP_REFERER using Javascript?

Just like the Title states…is it possible to get the HTTP REFERER using Javascript? I am coding a .htm page with no server side processing. I can grab it with ASP, but I need the extension to remain .htm

Not sure about version support:

document.write(location.referrer);
document.write(document.referrer);

I’ve seen both of these referenced.

I’ll give those a try and tell you what works.

document.referrer is the magic one!

Muchas Gracias, senor

Just a note that if they get to your site by clicking their favorites or by typing it in the location bar document.referrer will be empty.

True true. Same thing with ASP or probably any language for that fact. Still, most people will be visiting via a search engine for this site.

Cool, just what I wanted to know :smiley:

Just one thing, if I use frames, the frame won’t have the referer will it? Or can I use

parent.referrer

maybe?

OK that doesn’t work, could someone tell me how to get it pass it on? I tried this and it doesn’t work:


 <script>
document.write('<frame src="given.php?ref=' . document.referrer .'" name="nav" marginwidth="3" marginheight="3" scrolling="auto">' );
</script>

Try this…


document.write("<frame src='given.php?ref=" + document.referrer +" name='nav' marginwidth='3' marginheight='3' scrolling='auto'>");

Cheers, but still no luck. I tried removing everything else and putting all that’s left in the JS, like:


<script language="JavaScript">
document.write("<frameset cols='170,*' rows='*' border='2' framespacing='0' frameborder='yes'>
<frame src='given.php?ref=" + document.referrer +" name='nav' marginwidth='3' marginheight='3' scrolling='auto'><frame src='index.php?pane=right' name='main' marginwidth='10' marginheight='10' scrolling='auto'>
</frameset>);
</script>

but nothing, I’m thinking maybe that I can’t do this because frames have to be in a file with nothing else, so JS cannot do this?

Just curious…and I’m not sure that javascript can do that with frames…but you are clicking the link from the parent frame and you have this code in the child frame? Or are you typing in the URL for the page that has the code in it? Maybe there is another way to do what you want to accomplish. What’s the big picture?

I’m clicking the link from an entirely seperate page, with nothing but the link.

I was hoping to create a top-refers script, but this method wouldn’t work anyway. I wanted it for a site I’m working on, www.board.tk and .tk uses frames to load your site. Of course I’ve now realised that I don’t actually have any control over the frameset page anyway! I need to use a parent.location thing anyway to get out of frames as it plays havoc with cookies and P3P is hard to write. That is why I wanted parent.referrer to work as I could pass that on, but it looks impossible :bawling: