I'm using this to check if someone came from Reddit, however it doesn't work.
var ref = document.referrer; if(ref.match("/http://(www.)?reddit.com(/)?(.*)?/gi"){ alert('You came from Reddit'); } else { alert('No you didn\'t'); }
Suggestions on the regular expression are most welcome too.
To check the Referer in action go to Inspect Element -> Network check the request header for Referer like below. Referer header is highlighted. Supported Browsers: The browsers are compatible with HTTP header Referer are listed below: Google Chrome.
Your referrer is the page you're coming from. You can create a link to this page and click on it in order to check what URL If-So detects as the referral source. If you will not see your referrer above, that means neither If-So nor other services can track the referral source.
In more simple terms, the referer is the URL from which came a request received by a server. A good example is if you click a link on the page site.com/page to go to another-site.com/link, the HTTP Referer received by another-site.com/link will have the value site.com/page.
To try out the change in Chrome, enable the flag at chrome://flags/#reduced-referrer-granularity . You can also check out this demo to see the change in action. Beyond the referrer policy, the way browsers deal with referrers might change—so keep an eye on it.
Try this:
if (ref.match(/^https?:\/\/([^\/]+\.)?reddit\.com(\/|$)/i)) { alert("Came from reddit"); }
The regexp:
/^ # ensure start of string http # match 'http' s? # 's' if it exists is okay :\/\/ # match '://' ([^\/]+\.)? # match any non '/' chars followed by a '.' (if they exist) reddit\.com # match 'reddit.com' (\/|$) # match '/' or the end of the string /i # match case-insenitive
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With