Delay callback until script is added to document?

后端 未结 4 2190
名媛妹妹
名媛妹妹 2021-01-05 00:08

How can I get the callback to not run until the script is actually appended to the document?

function addScript(filepath, callback){
    if (filepath) {
             


        
4条回答
  •  没有蜡笔的小新
    2021-01-05 00:27

    This tiny script / css loader will do the job https://github.com/rgrove/lazyload/

    LazyLoad.js('/foo.js', function () {
      alert('foo.js has been loaded');
    });
    

提交回复
热议问题