Can I get the referrer?

I have a website on which I dynamically create Javascript code using ASP.NET handler in which I should add the referrer to a database.

I want to get referrer of referrer like so:

  • website1
  • website2 (where I create pixel to another site)
  • website3 (where pixel is located)

I don’t have code access to website1, on website2 I can only assign JavaScript.

If I get referrer in current application state I get website2.

Is there a way to get website1 as referrer?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can pass this value along: document.referrer.

That expression would need to be evaluated on website 2, not on website 3.


// website2.html
<img src="" id="pxl" />
document.getElementById('pxl').src += '?ref=' + encodeURIComponent(document.referrer);

The request to website3 will then include the referrer.

Method 2

It is impossible to get the referrer of website2 on website3 directly. However, since you can use javascript on website2, you could get the referrer (document.referrer) and add it to the url of the pixel you get. For example:

var referer = document.referrer;
var pixelUrl = 'http://website3/pixel?referrer=' + escape(referrer);
// create pixel...

Hope that helps

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x