Created
February 24, 2011 23:40
-
-
Save johnpena/843147 to your computer and use it in GitHub Desktop.
Dynamically load a javascript file
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(src, callback) { | |
| var head = document.getElementsByTagName('head')[0]; | |
| var new_script = document.createElement('script'); | |
| new_script.type = 'text/javascript'; | |
| new_script.src = src; | |
| // most browsers | |
| new_script.onload = callback; | |
| // IE 6 & 7 | |
| new_script.onreadystatechange = function() { | |
| if (this.readyState == 'complete') { | |
| callback(); | |
| } | |
| }; | |
| head.appendChild(new_script); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment