I’m writing a Javascript function to preload pictures on a website.
function preload(images) {
if (document.images) {
var i = 0;
var imageArray = new Array();
imageArray = images.split(';');
var imageObj = new Image();
for(i=0; i<=imageArray.length-1; i++) {
imageObj.src=images[i];
}
}
}
preload('img1.jpg;img2.jpg;img3.jpg');
It’s giving me an error:
Uncaught TypeError: Object # has no method ‘split’
What is causing this? How can i fix it?
Please let me know if I should provide more information,
Thanks!
Try it now, images[i] will not give you name of image. You have image names in imageArray. I changed images[i] to imageArray[i]