Skip to content

Instantly share code, notes, and snippets.

@blois
Created February 10, 2014 23:49
Show Gist options
  • Save blois/8926615 to your computer and use it in GitHub Desktop.
Save blois/8926615 to your computer and use it in GitHub Desktop.
Document.currentScript workaround
function getCurrentScript(callback) {
if (document.currentScript) {
callback(document.currentScript);
return;
}
var scripts = document.scripts;
function onLoad() {
for (var i = 0; i < scripts.length; ++i) {
scripts[i].removeEventListener('load', onLoad, false);
}
callback(event.target);
}
for (var i = 0; i < scripts.length; ++i) {
scripts[i].addEventListener('load', onLoad, false);
}
}
getCurrentScript(function(currentScript) {
window.console.log(currentScript.src);
});
@eric-nordicfactory
Copy link

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment