Illusionist
Illusionist

Reputation: 5509

document.referrer - limitations?

I am unable to get a lot of referral URLS using document.referrer. I'm not sure what is going on. I would appreciate it if anyone had any info on its limitations (like which browser does not support what) etc.

Is there something else i could use (in a different language perhaps) that covers more browsers etc?

Upvotes: 1

Views: 2159

Answers (4)

caisah
caisah

Reputation: 2087

The document.referrer will be an empty string if:

  • You access the site directly, by entering the URL;
  • You access the site by clicking on a bookmark;
  • The source link contains rel="noreferrer";
  • The source is a local file;

Check out https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer

Upvotes: 0

srenert1981
srenert1981

Reputation: 91

Which browser are you looking in? If the referring website is sending the traffic via window.open('some link') instead of a regular <a> tag, then IE will not see a referrer. It thinks it's a new request at that point, similar to you simply going to a URL directly (in which case there is no referrer). Firefox and Chrome do not have the same issue.

This is NOT just a javascript limitation, HTTP_REFERRER will NOT work either in this specific scenario.

Upvotes: 1

Tony Miller
Tony Miller

Reputation: 9159

Just to make sure you're on the same page, you do know that if someone types a URL directly in their web browser, the document.referrer property is empty, right? That being said, you might be interested in a JavScript method to get all HTTP headers. If you prefer PHP (since you're using that tag), the standard $_SERVER variable will provide what information is available. Note that the information is only as reliable as the reporting web browser and server, as noted by Kev.

Upvotes: 0

Kev
Kev

Reputation: 119856

I wouldn't put any faith in document.referrer in your Javascript code. The value is sent in client side request headers (Referer) and as such it can be spoofed and manipulated.

For more info see my answer to this question about the server side HTTP_REFERER server variable:

How reliable is HTTP_REFERER

Upvotes: 1

Related Questions