码迷,mamicode.com
首页 > 其他好文 > 详细

loadscript加载

时间:2014-11-05 00:10:12      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   java   for   sp   div   on   log   

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 );
}

 

loadscript加载

标签:blog   io   ar   java   for   sp   div   on   log   

原文地址:http://www.cnblogs.com/sntetwt/p/4075154.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!