preloading images

Hi

I've updated my website to contain a photo gallery. Each of the photos are stored on their own html page with links to previous and next html page, so that the viewer can see all the thumbnails on the gallery homepage and when they click on one photo it opens in a new window, which they can use to scroll through the larger images.

I am wanting to get it working so that when you are viewing one image, it pre loads the previous and next image. I have used the following code - which appears to work but it only seems to work once.

For example, if i open page1.html it displays pic1.jpg and pre-loads pic2.jpg - so when i scroll through to page2.html, the photo is already loaded. However, page2.html does not seem to pre load the pic3.jpg

The code i am using on each html page is :

<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- hide from none JavaScript Browsers
Image1= new Image($imagewidth,$imageheight)
Image1.src = "$pic"
// End Hiding -->
</SCRIPT>
</head>

where $pic is the image filename and $imagewidth and $imageheight are the width and height of the image

Does my problem come from the fact that each page is using the same name Image1?
or is it something else? Like i need to call something in the onload method?
[1361 byte] By [ambercelery] at [2007-11-19 23:21:19]
# 1 Re: preloading images
Hi,

Why not test wether it's the fact that you use the same name by using different names? At least then you can eliminate that option if it still doesn't work.

Also, what happens when the image gets preloaded and you changes pages? Does the browser know that you want to use the same image you preloaded on the previous page? Does it get it from cache? Or does it try download it again?

Why not display them all on the same page? That way you get rid of all the possible problems. When you build the page on the server just build in all the pictures paths, then just display one at a time and preload the next one when one is being viewed and use javascript to scroll through them?
Bnt at 2007-11-8 0:40:35 >