Does document.referrer equal the HTTP referer header?

被刻印的时光 ゝ 提交于 2020-02-24 17:31:04

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/49050268/does-document-referrer-equal-the-http-referer-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!