FLUSHER
FLUSHER

Reputation: 277

Does document.referrer equal the HTTP referer header?

If I follow a normal link from http://google.com to http://example.com, normally the http referrer header that my browser sends to example.com is of google.com. Is that header's value always the same as the value of document.referrer inside the example.com page?

Upvotes: 5

Views: 5203

Answers (1)

lofihelsinki
lofihelsinki

Reputation: 2571

The referer sent by the client in the request header is the same as document.referrer available in JavaScript. However, you can't rely that the referrer information would always be available.

It's up to the client to send the information. You can turn it off i.e. in the browser settings.

In Firefox: https://www.technipages.com/firefox-enable-disable-referrer

or you can turn it off with an extension.

In Chrome: https://chrome.google.com/webstore/detail/referer-control/hnkcfpcejkafcihlgbojoidoihckciin?hl=en

It's also easy to spoof / send whatever referer you want. With cURL for instance:

curl --referer http://whatever.com/bot.html http://www.example.com/

EDIT: You can also disable referrer sending in the page, so that links clicked or ajax calls made from that page won't send the referrer header. Just add this tag to the page.

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

More discussion here: https://stackoverflow.com/a/32014225/5601169

Upvotes: 5

Related Questions