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

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="https://stackoverflow.com/questions/2157396/someJSfile.js?referrer="+document.referrer;
 e.type="text/javascript";
 document.getElementsByTagName("head")[0].appendChild(e);
</script>

Leave a Comment