Published March 2, 2021
To check if the user came from a specific website or by clicking a link to your website, you can use the
referrer property in the global
// Check the link of website user came from const linkOfTheWebsiteUserCame = document.referrer;
- The property will return a string with the link if the user came from clicking on a link to your website and an empty string if the user came directly to your website by writing the URL on the browser URL area.
- This is useful if you want to give some conditional messages to your users who came from clicking on a special link from a website.
To check out this cool feature go to this JSBin link, then you can see the link of this blog you are reading shown there. Also if you refresh the page, it will show an empty string.