Skip to content

Instantly share code, notes, and snippets.

@johnteee
Created March 30, 2018 04:10
Show Gist options
  • Select an option

  • Save johnteee/14198fd661cf48df66307d5c9c1f334c to your computer and use it in GitHub Desktop.

Select an option

Save johnteee/14198fd661cf48df66307d5c9c1f334c to your computer and use it in GitHub Desktop.
function addScript(attribute, text) {
return new Promise(function(resolve, reject) {
var script = document.createElement('script');
for (var attr in attribute) {
var value = attribute[attr];
if (value) {
script.setAttribute(attr, value);
}
}
script.innerHTML = text;
script.onload = resolve;
script.onerror = reject;
document.body.appendChild(script);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment