Preload images


i’ve got a javascript question. i have a dropdown menu that i am placing on every page of my site. i don’ write the code for the menus on each page, rather i use an include file.

there are 13 images associated with the menu (trigger buttons, transparent gif, etc…). how can i preload these 13 images on each page of the site without having to use the onLoad function in the body tag and having to write 13 images on each page.

can i write a javascript function that’ll load these images by using an array?


function loadImage() {
img[1] = new Image
img[1].src =

Hey fumeng,
You are exactly correct. You need to use arrays to preload images. For a good site I found on this topic, visit:…lflip.html