Skip to content

Instantly share code, notes, and snippets.

@perymimon
Last active March 15, 2019 13:12
Show Gist options
  • Save perymimon/7a88a8242aa4627e4477 to your computer and use it in GitHub Desktop.
Save perymimon/7a88a8242aa4627e4477 to your computer and use it in GitHub Desktop.
inject script to current document for using in `javascript:` protocol
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