最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript document.referrer empty - Stack Overflow

programmeradmin1浏览0评论

I have been searching for many threads but I could not find the solution. I would like to get document.referrer but it always show empty. Its been so confusing. Here is my code

<script>
alert(document.referrer);
</script>

I got that code from w3schools. However, it is not work from my side. I have tried the code there and it works fine but not for mine.

I have an analysis that it is because my domain is under CloudFlare. Everyone knows that CloudFlare uses Proxy to redirect users before they go to our site but I would like to ask your opinion here. If it is not possible, is there any way I can do to pass http referrer? Thank you.

I have been searching for many threads but I could not find the solution. I would like to get document.referrer but it always show empty. Its been so confusing. Here is my code

<script>
alert(document.referrer);
</script>

I got that code from w3schools. However, it is not work from my side. I have tried the code there and it works fine but not for mine.

I have an analysis that it is because my domain is under CloudFlare. Everyone knows that CloudFlare uses Proxy to redirect users before they go to our site but I would like to ask your opinion here. If it is not possible, is there any way I can do to pass http referrer? Thank you.

Share Improve this question asked Oct 29, 2017 at 16:46 Drake BoeinDrake Boein 1171 silver badge11 bronze badges 2
  • 1 document.referrer is empty if you navigate from an https site to an http one, though even if I navigate from here to MDN it’s an empty string… – Sebastian Simon Commented Oct 29, 2017 at 16:54
  • is there any way I can do to retrieve it? – Drake Boein Commented Oct 29, 2017 at 16:57
Add a ment  | 

1 Answer 1

Reset to default 4

There is no way to retrieve the referral data if the host has set Referrer-Policy: no-referrer in their HTTP Header.

Since Cloudflare works as a reverse proxy it's not possible to get referral data in the same way as usual. You can read more here

Maybe Cloudflare keeps the data in your control panel, or you could find the correct data with tools like Google Analytics.

发布评论

评论列表(0)

  1. 暂无评论