what referrer is sent window.location.replace

Discussion in 'JavaScript' started by Wailua, Feb 8, 2008.

  1. #1
    Hi first time DP poster long time listener big up to Shawn and the mods!

    I'm trying to get clarification about which referrer is sent when using javascript redirect window.location.replace
    example:

    Site A links to

    Site B which immediately redirects with window.location.replace to site C

    from what I've tested Site C referrer using IE=no referrer and using Firefox=Site B using Opera=Site B (didn't test Safari)
    and back button goes back to Site A

    My intention is to redirect from site A to site C without site C detecting referrer from site A
    Will window.location.replace work for this purpose?



    PS
    This can be done with meta refresh though that breaks the back button.
     
    Wailua, Feb 8, 2008 IP
  2. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    To accomplish this, you can use server side 301 redirect, that will pass the original referrer. Server side programming like PHP, asp or even CF.
     
    imvain2, Feb 8, 2008 IP
  3. Wailua

    Wailua Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply. I don't want to pass the original referrer

    My intention is to redirect from site A via a redirect on site B to site C without site C detecting referrer from site A- also back button will take user back to site A
    As far as I can see window.location.replace will do this. Can anyone confirm this or suggest any shortcomings of using this redirect?
     
    Wailua, Feb 11, 2008 IP
  4. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    1. Do you want Site B to be passed as the referrer to Site C (and keep Site A's URL hidden), or do you want a blank referrer to be passed to Site C?

    2. If the user hits the back button, do you want them to go back to Site A or Site B?
     
    vpguy, Feb 15, 2008 IP
  5. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #5
    @vpguy
    1. He probably doesn't care, just doesn't want Site A's URL to show
    2. Wants it to go to Site A when hitting back


    Well, from the sound of your tests, your method will work fine. You don't have to use document.location.replace though. You can simply do document.location = "new site";

    I do not think the method I've provided will change any of your results so you should be good to go.
     
    zerxer, Feb 15, 2008 IP
  6. Wailua

    Wailua Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks Zerxer- yes correct on both points

    Is there advantage to document.location versus window.location.replace? such as speed of redirect or browser compatibility?
     
    Wailua, Feb 19, 2008 IP
  7. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Actually, I have never used document.location.replace myself, so I decided to look it up. Setting document.location (example: document.location = "new url";) will just load the new page while doing document.location.replace("new url") will load the new page and replace the current page in the user's History with the new one. I'm pretty sure with what you're trying to do, you'd rather use document.location.replace() so that Site B does not show in the history? Yes, because that would stop it from going back to that page when they hit the Back button.

    (I use document instead of window but I honestly don't know the difference between the two when changing the location. There might be compatibility differences but I think most sites recommend you use document.*)
     
    zerxer, Feb 19, 2008 IP