📜  延迟外部 javascript 文件加载 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:20.932000             🧑  作者: Mango

代码示例1
//load external js file into header after 2 seconds
setTimeout(function() {
    var headerEl = document.getElementsByTagName("head")[0];   
    var scriptEl = document.createElement('script');
        scriptEl.type = 'text/javascript';
        scriptEl.src = 'http:/www.mywebsite.com/myscript.js';
        headerEl.appendChild(scriptEl);
}, 2000);