2

I want to build my own analytic and I need to know from where the requests are coming from with only javaScrpt, I can't believe that the browser is not holding somewhere in window object a variable about from where the request came from. It looks like there is no information in the net or I am not asking the right question.

I hope somebody met this problem before and has a solution :) Thanks!

enter image description here

1 Answer 1

3

You can use document.referrer

Syntax

var referrer = document.referrer; 

Value

The value is an empty string if the user navigated to the page directly (not through a link, but, for example, by using a bookmark). Because this property returns only a string, it doesn't give you document object model (DOM) access to the referring page.

Inside an <iframe>, the Document.referrer will initially be set to the same value as the href of the parent window's Window.location.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Pedro, It worked as I needed :) I just want to add for future dudes with the same problem... So when I tried "document.referrer" from One of my website to the one in development I got again an empty string. I found that If the request is from https to http (which was my case) we have the same empty result. I built the site and hosted to an https domain and everithing worked just fine. Thanks again ! The source of my knowege about https to http document.refferer empty string link

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.