Reputation: 1091
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!
Upvotes: 2
Views: 2153
Reputation: 98901
You can use document.referrer
var referrer = document.referrer;
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
.
Upvotes: 3