javascriptreferralsbrowser-tab

Get referral Url in new tab


If you click on a link and it opens in a new tab, in that new tab you have some Javascript that gets the referral url but the referral url equals nothing or undefined.

I want to know if it is possible to get the referral url even when the link has been opened in a new tab.


Solution

  • Yes this is doable. In the new tab's JavaScript you can write

    alert(document.referrer);
    

    Know more about Document Referrer.

    You can also do this in PHP. Check this Get original URL referer with PHP