Skip to content

Instantly share code, notes, and snippets.

@chsh
Created May 7, 2011 15:57
Show Gist options
  • Save chsh/960601 to your computer and use it in GitHub Desktop.
Save chsh/960601 to your computer and use it in GitHub Desktop.
Build javascript load path using a dir itself.
var SCRIPT_NAME = 'my_name.js';
function getScriptPath(target) {
var list = document.getElementsByTagName("script");
var i = list.length;
while (i--) {
var src = list[i].src;
if (src) {
var result = src.match(/^(.*)([^\/]+\.js)$/);
if (result) {
if (result[2] == SCRIPT_NAME) {
return result[1] + target;
}
}
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment