美文网首页Javascript
动态插入script标签

动态插入script标签

作者: anefish | 来源:发表于2017-11-14 16:14 被阅读0次
            function callback() {
            }
    
            // 插入script标签并监听加载
            var head = document.getElementsByTagName('head')[0];
            var script = document.createElement('script');
            script.type= 'text/javascript';
            script.onload = script.onreadystatechange = function() {
              if (!this.readyState || this.readyState === "loaded" 
                                            || this.readyState === "complete" ) {
                callback();
                // Handle memory leak in IE
                script.onload = script.onreadystatechange = null;
              }
            };
            script.src= scriptSrc;
            head.appendChild(script);
    

    相关文章

      网友评论

        本文标题:动态插入script标签

        本文链接:https://www.haomeiwen.com/subject/lzdfvxtx.html