function loadImage(url, callback) { if(url!='null') { var img = new Image(); img.src = url; if(img.complete) { callback(img); } else { img.onload = function(){ img.onload = null; callback(img); } } } } loadImage(pic_url,loadImage);