0

A common asynchronous download js function as follows.

But when the download fails, how to call the error function.

This function will be: function loadScript(url, callback, errcb).

function loadScript(url, callback){ 
    var script = document.createElement("script") 
    script.type = "text/javascript"; 
    if (script.readyState){ //IE 
        script.onreadystatechange = function(){ 
            if (script.readyState == "loaded" || script.readyState == "complete"){ 
                script.onreadystatechange = null; 
                callback(); 
            } 
         }; 
    } else { //Others: Firefox, Safari, Chrome, and Opera 
        script.onload = function(){ 
            callback(); 
        }; 
    } 
    script.src = url; 
    document.body.appendChild(script); 
} 
simon
  • 569
  • 9
  • 20
  • you can find some information find from this blog http://www.jspatterns.com/the-ridiculous-case-of-adding-a-script-element/ – rab Mar 05 '13 at 08:21
  • try this link http://stackoverflow.com/questions/538745/how-to-tell-if-a-script-tag-failed-to-load – rab Mar 05 '13 at 09:10

0 Answers0