I know I can grab the entire referring url by using:
document.referrer
But how would I only grab the base domain of the referrer?? So:
if(document.referrer === subdomain.domain.com){
}
So all referring urls coming from that main domain would work and all strings coming after the base domain are ignored.
At its simplest, just check
document.referrer.indexOf("example.com") > -1. The downside of this is that if the referring page ishttp://somethingevil.com/pages/example.comthen you’ll get a false match on the check.You could go for a regex, something like:
/^https?:\/\/example\.com\//as this will be more reliable of a check, but a harder one to cover edge cases like subdomains, ports, accessing via the IP address, etc..