Languages
[Edit]
EN

JavaScript - get source page URL (source: referral)

6 points
Created by:
Wiktor-Sribiew
830

In this short article, we would like to show you how get website URL from which the user came using JavaScript in web browser.

Quick solution:

 

Note: sometimes document.referrer can be empty depending on possible rel="noreferrer" attribute used in the source link.

Hint: it is good to consider using UTM links to detect source if it is possible.

 

Example results

Edit

Possible document.referrer values may look like:

 

Practical example

Edit

Note: copy source code and paste it to your website to see correct effect.

 

See also

Edit
  1. JavaScript - detect if user entered webpage directly (source: direct)

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join