Skip to content

Instantly share code, notes, and snippets.

@clichedmoog
Created September 1, 2017 18:42
Show Gist options
  • Save clichedmoog/ebea9a6198ea99ce66f79b7845cd81b0 to your computer and use it in GitHub Desktop.
Save clichedmoog/ebea9a6198ea99ce66f79b7845cd81b0 to your computer and use it in GitHub Desktop.
get javascript path dynamically
function getScriptPath(filename) {
var scripts = document.getElementsByTagName('script');
if (scripts && scripts.length > 0) {
for (var i in scripts) {
if (scripts[i].src && scripts[i].src.match(new RegExp(filename+'\\.js$'))) {
return scripts[i].src.replace(new RegExp('(.*)'+filename+'\\.js$'), '$1');
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment