Problem while dynamic loading js files

Hi

I have a requirement to dynamic load js files when game is running

I checked the source of jsloader.js and made coding like these:

createJsDocument:function(que){ var loaded = 0; var d=document; if (navigator.userAgent.indexOf("Trident/5") > -1) { //ie9 this.serial = -1; var loadNext = function () { var s = this.serial + 1; if (s < que.length) { var f = d.createElement('script'); f.src = que[s]; f.serial = s; f.onload = loadNext; d.body.appendChild(f); p = s / (que.length - 1); } }; loadNext(); } else { que.forEach(function (f, i) { var s = d.createElement('script'); s.async = false; s.src = f; s.onload = function () { loaded++; p = loaded / que.length; }; d.body.appendChild(s); que[i] = s; }); } }

when the function createJsDocument had been called,I found the html changed in the browser ,

the script segment:

had been inserted, but the function in this script(a.js) was still undifined. Can everybody help me?Any help would be greatly appreciated

Hi Bruce Li,

The functions in your script(a.js) have been defined until the status of this script file is loaded(“onload” event has been called).