Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the Url Referer via a javascript include?

If I search for something on google and click on a result (mytestsite.com), the referer to that site will be URL of the google search.

Now on that site, there is a JS file include that is used for tracking purposes..however the referrer to that JS file request is mytestsite.com...is there no way for the server handling the JS request to know that it originated from a google search?

like image 292
puffpio Avatar asked Jan 28 '10 19:01

puffpio


People also ask

How do I get referer in Javascript?

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...

How do I get a referrer URL?

There is a global variable in PHP that contains the referred URLs, called “$_SERVER.” The “$_SERVER” variable includes the “HTTP_REFERER” element that will return the referrer URLs. The combining “$_SERVER['HTTP_REFERER']” variable will display the complete URLs of the webpage that the current page is linked from.

How do you get referer?

To check the Referer in action go to Inspect Element -> Network check the request header for Referer like below. Referer header is highlighted. Supported Browsers: The browsers are compatible with HTTP header Referer are listed below: Google Chrome.

What is URL referrer?

The address of the webpage where a person clicked a link that sent them to your page. The referrer is the webpage that sends visitors to your site using a link. In other words, it's the webpage that a person was on right before they landed on your page.


1 Answers

I'm a little unclear on what you are trying to do, but you can grab the referrer with JavaScript using:

document.referrer 

...and pass it along to the server in your request for the JS file. Several ways to do this...here's one:

<script>  var e = document.createElement("script");  e.src = 'someJSfile.js?referrer='+document.referrer;  e.type="text/javascript";  document.getElementsByTagName("head")[0].appendChild(e); </script> 
like image 133
droo Avatar answered Sep 22 '22 13:09

droo