thescor420 thescor420 - 2 months ago 10
Javascript Question

External domain JavaScript referrer? how it works?

so I have a question and I can't find an answer.

So I have a domain dario1.com which has a button that redirects to dario2.com

dario2.com has an JS code to tell the referrer and if te referrer is dario1 it will run a JS. And that works perfectly.

var ref1= document.referrer;
var search = "dario1";
if (ref1.indexOf(search) > -1)
do_something();
else
void(0);


My question is:
If dario2.com has this code(in head tags) in an external JS on another domain like asdf.com(which i dont own).Can the asdf.com site tell my referrer? Or it will show dario2.com?

type="text/javascript" src="http://asdf.com/referrer.js"


I dont know how to test this(don't own more domains, also jsfiddle is kinda embeed so I don't know if it's good.), and also I want to be sure.

Answer

javascript runs on the local machine only. So anything you put in the src= attribute is basically telling your client to request the code from a particular location and run it locally. It does not matter where the code comes from, it will always be run the same!

The only way to access where the code came from (see what is inside the src attribute), is to look at the dom itself.

So to recap, the code you have pasted in your question will always run exactly the same, no matter where is was requested from.