Created
February 10, 2014 23:49
-
-
Save blois/8926615 to your computer and use it in GitHub Desktop.
Document.currentScript workaround
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 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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome!