SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    UK
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure about version support:

    Code:
    document.write(location.referrer);
    document.write(document.referrer);
    I've seen both of these referenced.

  3. #3
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll give those a try and tell you what works.

  4. #4
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.referrer is the magic one!

    Muchas Gracias, senor

  5. #5
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    Probably eating pie mitsubishi's Avatar
    Join Date
    Sep 2001
    Location
    England, UK
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool, just what I wanted to know

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

    parent.referrer

    maybe?

  8. #8
    Probably eating pie mitsubishi's Avatar
    Join Date
    Sep 2001
    Location
    England, UK
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK that doesn't work, could someone tell me how to get it pass it on? I tried this and it doesn't work:

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

  9. #9
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this...

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

  10. #10
    Probably eating pie mitsubishi's Avatar
    Join Date
    Sep 2001
    Location
    England, UK
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers, but still no luck. I tried removing everything else and putting all that's left in the JS, like:
    Code:
    <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?

  11. #11
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  12. #12
    Probably eating pie mitsubishi's Avatar
    Join Date
    Sep 2001
    Location
    England, UK
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •