How can a javascript file know where it is located? For example:
Try:
document.scripts[document.scripts.length-1]; // add .src to get href
//or
document.getElementsByTagName("script")[document.getElementsByTagName("script").length-1];
//for (maybe) better compatibility
Which gets the last script in the DOM. If your script is being executed while it is being loaded, this will return the right element.
Save it to a variable for use in functions which will be used later.
var thisScript = document.scripts[document.scripts.length-1];