Created
September 1, 2017 18:42
-
-
Save clichedmoog/ebea9a6198ea99ce66f79b7845cd81b0 to your computer and use it in GitHub Desktop.
get javascript path dynamically
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
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