Last active
December 31, 2019 21:37
-
-
Save Thecarisma/f1fac7988b19981980752cae9f66352a to your computer and use it in GitHub Desktop.
Load a remote javascript file in the browser synchronously. Wait till loading complete with callback.
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
//Example: log 'Hello World' after language-colors.css load completed | |
/** | |
loadScript("https://quickutils.github.io/language-colors/language-colors.css", function() { | |
console.log('Hello World'); | |
}); | |
**/ | |
function loadScript(url, callback) { | |
var head = document.body; | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = url; | |
script.onreadystatechange = callback; | |
script.onload = callback; | |
head.appendChild(script); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment