Languages

JavaScript - how to detect from where user came?

8 points
Asked by:
Ela-Davey
663

I am looking for the best way how to detect from where user came to my web page.

I know there is referrer header in HTTP protocol. Is it possible to get in JavaScript in web browser that kind of information?

1 answer
10 points
Answered by:
Ela-Davey
663

Yes, it is possible. Use document.referrer property.

e.g.

const url = document.referrer;

if (url) {
    // as example `url` variable can be equal to 'https://google.com' when user came directly from google.com domain.
}

 

See also

  1. JavaScript - get referrer URL (user source URL) - v1

  2. JavaScript - get referrer URL (user source URL) - v2

0 comments Add comment
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