views:

466

answers:

2

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?

A: 

There's no way with an ordinary script tag. If you're loading a script from the same domain you could get it with XHR and eval it, although I wouldn't really recommend it. With the XHR you can set the referer header yourself:

xhr.setRequestHeader("referer", "http://www.google.com/search?q=hello");

Another alternative might be to use a proxy that strips out the referrer.

Andy E
A: 

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