What is the most reliable way to hide / spoof the referrer in JavaScript?

前端 未结 10 1499
挽巷
挽巷 2020-11-28 03:13

Normally, the referrer is traceable through:

  • JavaScript\'s document.referrer
  • The request headers, e.g. PHP\'s $_SERVER[\'HTTP_REFER
相关标签:
10条回答
  • 2020-11-28 03:37

    Can't you create a linking system that resides within iframes?

    If you wrap an iframe around every link, the iframe can act as an external de-refer. The user would click on the link inside the frame, opening a page whose referrer is set to the iFrame's location, instead of the actual page.

    0 讨论(0)
  • 2020-11-28 03:42

    There is a cross browser solution in Javascript that removes the referrer, it uses Iframes created dynamically, you can take a look to a proof of concept ( disclaimer: it uses a little JS library I wrote ).

    0 讨论(0)
  • 2020-11-28 03:43

    A very comprehensive (but short) analysis can be found at:

    http://lincolnloop.com/blog/2012/jun/27/referrer-blocking-hard/

    this article analyses both methods explained in other answers (js method, iframe redirecting) and finally suggest a mediate redirector page approach, like the one seen in google search links.

    0 讨论(0)
  • 2020-11-28 03:44

    As requested, by using JavaScript:

    var meta = document.createElement('meta');
    meta.name = "referrer";
    meta.content = "no-referrer";
    document.getElementsByTagName('head')[0].appendChild(meta);
    

    This will add the following meta tag to head section of the web page:

    <meta name="referrer" content="no-referrer" />
    

    As of 2015 this is how you prevent sending the Referer header.

    0 讨论(0)
提交回复
热议问题