Last active
October 27, 2015 02:26
-
-
Save think2011/bc4f6390332a3c7b806c to your computer and use it in GitHub Desktop.
获取js所在路径
This file contains hidden or 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 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