Javascript

动态插入script标签

2017-11-14  本文已影响0人  anefish
        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);
上一篇下一篇

猜你喜欢

热点阅读