View Full Version : pre-loading on other pages

07-09-2002, 05:37 AM
I've seen various Q&As on various forums about pre-loading images here, but at my level of complete Javascript beginner...well, so many options are just confusing. I'm not sure even which apply to my situation, so I hope someone can give me a simple answer.

On my top page there's a link to a 'photos' page. On that page will be maybe 20 thumbnails. The user can click on any one and a bigger version will appear in the frame. I've put each large version on its own HTML page (not how the experts would do it, I'm sure, but it's sufficient). On each of the pages are back and forward arrows so the viewer can cycle through the bigger pics in the order of the thumbnails (I'm using LOWSRC, by the way).

What I want is to put some code on each page to pre-load the next and previous 2 (more?) pictures in the cycle, for the obvious reason. So can I just use the simple

<script language="javascript">
img02.src=images/image2.jpg ;

on each page? I'm under the impression it doesn't work if the images are on another page (I'm wondering if a link can be followed to cache from a new page, even if the url is the same), but I could be completely misguided.

Also, if I preload images should I delete all the LOWSRC references?

Thanks for any help.

07-10-2002, 03:41 AM
Thanks a lot, Dave. The code below appears to cache images for another page. I know it works because I can see it working. Without pre-loading, my computer is slow enough that I can see the "alt" title before an image loads, but with the pre-loading the images come up immediately. (And of course the low res images are not necessary).

<script language="javascript">
//images for use on another page
function preload(){
image1=new Image(h,w);
image2=new Image(h,w);
<body onLoad="preload();">