MetaTron
MetaTron

Reputation: 1091

Detect from where (which website) the http request came from

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

Upvotes: 2

Views: 2153

Answers (1)

Pedro Lobito
Pedro Lobito

Reputation: 98901

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.

Upvotes: 3

Related Questions