6

I need to do a Javascript based redirect

window.location.href = 'URL';

But I need to remove the referrer from the HTTP headers upon redirection (the target page should see no referrer), how can I do that?

Flavien
  • 7,497
  • 10
  • 45
  • 52
  • Here is a simple trick using iframes and https: http://stackoverflow.com/a/30304058/2440 – Sire May 18 '15 at 13:19

5 Answers5

4

<a href="redirecturl" rel="noreferrer" id="autoclick">Link</a>
<script>document.getElementById('autoclick').click();</script>
bas
  • 52
  • 3
1

There is but as far as I know it's not beautiful. Check the first answer here

Community
  • 1
  • 1
  • That's not just *not beautiful*, that's plain fugly. And it's so terribly hacky I wouldn't depend on it. Furthermore, it only works for linking images, **not for redirects, nor can it**, so it doesn't answer the question. – Niels Keurentjes May 07 '13 at 09:58
0

If you only going to do this for location redirect, then you can set up a bridge page hosted somewhere less sensitive and doesn't do anything other than redirect. Now you can link all the destination to http://<redirect_page>?<actual_url>

window.location.href= window.location.href.split("?")[1];

user227353
  • 2,594
  • 2
  • 15
  • 13
0

I know that this question has been inactive for a while, found it browsing the web and found a nice answer that may help save another person's time. This version uses JQuery.

$(function(){

  $("#button").on("click", function(){
      $("head").append('<meta name="referrer" content="no-referrer"/>');
      window.location = "http://www.example.org";
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button id="button">Click to navigate</button>
capote1789
  • 76
  • 6
-2

You can't. It's up to the browser to set referrer headers or not, the script has no influence on it.

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136