Skip to content

Latest commit

 

History

History
49 lines (42 loc) · 1.16 KB

load js css script later.md

File metadata and controls

49 lines (42 loc) · 1.16 KB

create a function and call it

 function loaded() {
 
 //window load
 }

first add the window loaded code

window.addEventListener('load', function () {
//css
//js code goes here
}

add js code

let jsImportArray = [
          "https://hspwidget.html5.run/index.js",
          "./assets/js/alljs.js",
        ];
        jsImportArray.forEach((item, index) => {
          console.log("js Import Started")
          let script = document.createElement('script');
          script.src = item;
          document.getElementsByTagName('head')[0].appendChild(script);
          console.log("js Import ended")
        })
        

for css

 let cssImportArray = [
         "@import url('https://hspwidget.html5.run/index.css');",
       ]

       cssImportArray.forEach((item, index) => {
         console.log("css import Started")
         let styles = item;
         let newSS = document.createElement('link');
         newSS.rel = 'stylesheet';
         newSS.href = 'data:text/css,' + escape(styles);
         document.getElementsByTagName("head")[0].appendChild(newSS);
         console.log("css import ended")
       })