Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

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];

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>

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top