Skip to content

Instantly share code, notes, and snippets.

@think2011
Last active October 27, 2015 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save think2011/bc4f6390332a3c7b806c to your computer and use it in GitHub Desktop.
Save think2011/bc4f6390332a3c7b806c to your computer and use it in GitHub Desktop.
获取js所在路径
function getJsDir (src) {
var script = null;
if (src) {
script = [].filter.call(document.scripts, function (v) {
return v.src.indexOf(src) !== -1;
})[0];
} else {
script = document.scripts[document.scripts.length - 1];
}
return script ? script.src.substr(0, script.src.lastIndexOf('/')) : script;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment