Created
February 16, 2010 10:49
-
-
Save jakearchibald/305450 to your computer and use it in GitHub Desktop.
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 loadScript(url, callback) { | |
| var script = document.createElement('script'), | |
| head = document.getElementsByTagName('head')[0]; | |
| // two methods for detecting when scripts have loaded | |
| script.onreadystatechange = function () { | |
| if (script.readyState == 'loaded' || script.readyState == 'complete') { | |
| callback(); | |
| } | |
| } | |
| script.onload = callback; | |
| script.src = url; | |
| head.insertBefore(script, head.lastChild); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment