Last active
March 15, 2019 13:12
-
-
Save perymimon/7a88a8242aa4627e4477 to your computer and use it in GitHub Desktop.
inject script to current document for using in `javascript:` protocol
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
function loaderScript(scriptUrl){ | |
return new Promise(function (res, rej) { | |
let script = document.createElement('script'); | |
script.src = scriptUrl; | |
script.type = 'text/javascript'; | |
script.onError = rej; | |
script.async = true; | |
script.onload = res; | |
script.addEventListener('error',rej); | |
script.addEventListener('load',res); | |
document.head.appendChild(script); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment