Created
December 12, 2012 14:40
-
-
Save jnrbsn/4268258 to your computer and use it in GitHub Desktop.
Loads a JavaScript file asynchronously with a callback, like jQuery's `$.getScript()` except without jQuery.
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 j(u, c) { | |
var h = document.getElementsByTagName('head')[0], s = document.createElement('script'); | |
s.async = true; s.src = u; | |
s.onload = s.onreadystatechange = function () { | |
if (!s.readyState || /loaded|complete/.test(s.readyState)) { | |
s.onload = s.onreadystatechange = null; if (h && s.parentNode) { h.removeChild(s) } s = undefined; | |
if (c) { c() } | |
} | |
}; | |
h.insertBefore(s, h.firstChild); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much!
http://forum.isystems.am/wiki/262/loads-a-javascript-file-asynchronously-with-a-callback-like-jquerys-getscript-except-without-jquery