Created
July 13, 2013 07:16
-
-
Save E01T/5989765 to your computer and use it in GitHub Desktop.
Dynamic, cross-browser script loading - from head.js lib
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
// From the headjs code: | |
function scriptTag(src, callback) { | |
var s = doc.createElement('script'); | |
s.type = 'text/' + (src.type || 'javascript'); | |
s.src = src.src || src; | |
s.async = false; | |
s.onreadystatechange = s.onload = function() { | |
var state = s.readyState; | |
if (!callback.done && (!state || /loaded|complete/.test(state))) { | |
callback.done = true; | |
callback(); | |
} | |
}; | |
// use body if available. more safe in IE | |
(doc.body || head).appendChild(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment