-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Open
Description
I'd like to see this become possible, since it would simplify my dependency handling when it involves scripts loaded from a different origin. Should be possible using the error
event, as with this code snippet I swiped from MDN:
var importScript = (function (oHead) {
function loadError (oError) {
throw new URIError("The script " + oError.target.src + " is not accessible.");
}
return function (sSrc, fOnload) {
var oScript = document.createElement("script");
oScript.type = "text\/javascript";
oScript.onerror = loadError;
if (fOnload) { oScript.onload = fOnload; }
oHead.appendChild(oScript);
oScript.src = sSrc;
}
})(document.head || document.getElementsByTagName("head")[0]);
importScript("myScript2.js", /* onload function: */ function () { alert("You read this alert because the script \"myScript2.js\" has been correctly loaded."); });