How to dynamically load Cascading Style Sheet (CSS) and JS sources within Javascript
2020-01-22 00:00:00
IN1
,
2023-04-10 14:16:30
IN1
Loading JavaScript
simple
var oScript = document.createElement('script');
oScript.src = 'URL';
document.head.appendChild(oScript);
with callback
var oScript = document.createElement('script');
oScript.onload = function () {
// ...code...
};
oScript.src = 'URL';
document.head.appendChild(oScript);
Loading CSS
var oLink = document.createElement('link');
oLink.id = cssId;
oLink.rel = 'stylesheet';
oLink.type = 'text/css';
oLink.href = 'URL';
oLink.media = 'all';
var oHead = document.getElementsByTagName('head')[0];
oHead.appendChild(oLink);