I am loading javascript dynamically and accessing its variable. I checked the second answer from this question and the following code works beautifully.
include = function (url, fn) {
var e = document.createElement("script");
e.onload = fn;
e.src = url;
e.async=true;
document.getElementsByTagName("head")[0].appendChild(e);
};
include("test.js",function(){
console.log(foo);
});
QUESTION: I want to have a onFailure callback function as well that allows me to process code in case
- The internet is down.
- The filename is not accessible (eg: incorrect path)
Will appreciate if someone can guide me to the right direction. Thanks