Created
April 26, 2013 14:27
-
-
Save jasdeepkhalsa/5467729 to your computer and use it in GitHub Desktop.
Load a script via JavaScript and run a callback when its loaded
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 loadBackupScript(callback){ | |
| if (typeof callback !== 'function') { | |
| throw 'Not a valid callback'; | |
| } | |
| var script = document.createElement('script'); | |
| script.src = 'http://www.geoplugin.net/javascript.gp'; | |
| script.type = 'text/javascript'; | |
| script.onload = callback; | |
| var head = document.getElementsByTagName("head")[0]; | |
| head.appendChild(script); | |
| } | |
| // Usage: | |
| loadBackupScript(function() { alert('loaded'); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment