Ways to add javascript files dynamically in a page

后端 未结 9 1646
盖世英雄少女心
盖世英雄少女心 2020-11-28 09:16

I have seen Scriptaculous.js file to include its required javascript files dynamically. Is there any better approach to include javascript dynamically.

For example,

9条回答
  •  旧时难觅i
    2020-11-28 09:41

    We can quickly extend this so that a callback can be performed once the script is added.

    function loadjscssfile(filename, filetype, callback){
        if (typeof fileref!="undefined") {
            document.getElementsByTagName("head")[0].appendChild(fileref);
            callback();
        }
    }
    

提交回复
热议问题