Skip to content

Instantly share code, notes, and snippets.

@ZiTAL ZiTAL/inline.js
Last active Apr 25, 2019

Embed
What would you like to do?
js: dynamic js load
(function()
{
'use strict';
function loadJs(ar, f)
{
var head = document.querySelector('head');
var l = ar.length;
var count = 0;
for(var i in ar)
{
(function(url)
{
var s = document.createElement('script');
s.addEventListener ("load", function()
{
console.log("loadJs: "+this.src);
count++;
if(count===l && typeof f ==='function')
f();
}, false);
s.addEventListener ("error", function()
{
console.error("loadJs: error loading "+this.src);
count++;
if(count===l && typeof f ==='function')
f();
}, false);
s.src = url;
head.append(s);
})(ar[i]);
}
}
window.loadJs = loadJs;
})();
// adibidea
(function()
{
loadJs([
'https://www.eitb.eus/resources/js/jquery-3.2.1.min.js'
],
function()
{
console.log('jquery kargatuta');
loadJs([
'https://unpkg.com/jscroll@2.4.1/dist/jquery.jscroll.min.js',
'https://www.eitb.eus/resources/js/swiper/swiper4.js'
],
function()
{
console.log('amaitu da');
});
}
);
})();
@ZiTAL

This comment has been minimized.

Copy link
Owner Author

commented Apr 25, 2019

ordenan karga bidotez, ostantxien peta lei

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.