Created
May 7, 2011 15:57
-
-
Save chsh/960601 to your computer and use it in GitHub Desktop.
Build javascript load path using a dir itself.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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