Front & Back Development

Load Javascript source Dynamically


function loadJavaScriptOnDemand(src, callback) {
var script = document.createElement('script');
script.src = src;
document.getElementsByTagName('head')[0].appendChild(script);

script.onreadystatechange = function() {
if (script.readyState == 4 || script.readyState == "complete") {

if (typeof callback == "function") {
callback();
}
callback = null;
}
}
}

Above function you can call as following.

loadJavaScriptOnDemand(‘path/to/your/javascript’,function(){alert(‘JavaScript loaded’)});

Beto López
"Full stack" web developer focused in maintenance and bug fixing.Wordpress, Prestashop, HTML, CSS, Javascript, Php and Mysql. Also open source collaborator. Linkedin y Twitter.


We've got your back
Get business from your website, not headaches. Leave your email and we'll contact you

1
Hi! 👋Beto here, may I help you?
Powered by