10月 112009
 

    var loadScript = function(src,callback,cache){
        var 
s=document.createElement("script");
        
s.type="text/javascript";
        
s[document.all?"onreadystatechange":"onload"] = function(){
            if(
document.all&&this.readyState!="loaded"&&this.readyState!="complete"){
                return; 
            }       
            
this[document.all?"onreadystatechange":"onload"]=null;
            
this.parentNode.removeChild(this);
            if(
callback != undefinedcallback();
        };      
        if(!
cachesrc += (/?/.test(src)?"&":"?") + "_=" + (new Date()).getTime();
        
s.src src;                                                              
        
document.getElementsByTagName("head")[0].appendChild(s);                  
    }

注意的问题:
1.  Firefox下的onload事件是在正常加载完毕后出发的,如果是404或500等错误,则不会触发onload事件,这时回调函数就没时候执行了。

 Posted by at 下午 10:24

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据