Skip to content

Instantly share code, notes, and snippets.

@tianyk
Created June 3, 2020 06:49
Show Gist options
  • Save tianyk/9a3be3a84d13514423dae101a0c33574 to your computer and use it in GitHub Desktop.
Save tianyk/9a3be3a84d13514423dae101a0c33574 to your computer and use it in GitHub Desktop.
var importScript = (function (oBody) {
return function (sSrc, fOnload) {
var oScript = document.createElement('script');
oScript.type = 'text\/javascript';
if (typeof fOnload === 'function') {
oScript.onerror = function (evt) {
fOnload(new URIError('The script ' + evt.target.src + ' is not accessible.'));
};
oScript.onload = function () {
fOnload();
};
}
oBody.appendChild(oScript);
oScript.src = sSrc;
}
})(document.body || document.getElementsByTagName('body')[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment