Forum Moderators: open
the problem i am having is probably a relatively dummy one but i just cant seem to find my way out of it...
i wanna preload a couple of images, but without specifying their names, but with a generic function
thats the code: (a lot of variables i know, but that way i find it easier to keep track of stuff :)
function preload(ext) {
var imageCache = new Array();
var imgArray = document.getElementsByTagName("img");
for (i=0; i<imgArray.length; i++) {
if (imgArray[i].className == "preload"){
var filepath = imgArray[i].src;
var sl = filepath.length-4;
var filename = filepath.substring(sl, 4);
imageCache[imageCache.length] = new Image();
imageCache[imageCache.length-1].src = filename + "_over." + ext;}
}
}
as you can see i grab all img tags with a class="preload", crop away last for characters (.gif or .png), add _over and join this all back with the appropriate extension
then i am just invoking the function, for example preload('gif') within body onload
strangely, it does not seem to work
i tried 'alerting' every part of the code -> everything seems to be fine
damn me, but what am i doing wrong?