there're about a million scripts for this, but here's mine:
Code:
function preLoad(args){
if (document.images){
var img = new Image();
var failed = [];
img.onerror = function(){
failed[failed.length] = this.src;
if(args.length > 0){ this.src = args.shift(); }
}
img.onload = function(){
if(args.length > 0){ this.src = args.shift(); }
}
img.src = args.shift();
}
else { var failed = args; }
return failed;
}
use it like this:
Code:
preLoad(["pictures/navbarbg2.jpg"]);
preLoad(["preloading.jpg", "multiple.png", "files.gif"]);