function load_script(xyUrl, callback){
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = xyUrl;
    //借鉴了jQuery的script跨域方法
    script.onload = script.onreadystatechange = function(){
        if((!this.readyState || this.readyState === "loaded" || this.readyState === "complete")){
            callback && callback();
            // Handle memory leak in IE
            script.onload = script.onreadystatechange = null;
            if ( head && script.parentNode ) {
                head.removeChild( script );
            }
        }
    };
    // Use insertBefore instead of appendChild  to circumvent an IE6 bug.
    head.insertBefore( script, head.firstChild );
}

 

相关文章:

  • 2021-11-17
  • 2022-02-07
  • 2022-12-23
  • 2021-09-20
  • 2022-01-07
  • 2021-09-16
  • 2022-02-07
猜你喜欢
  • 2021-05-17
  • 2021-12-27
  • 2022-12-23
  • 2021-08-26
  • 2021-05-05
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案