View Full Version : Preloading image

03-20-2005, 09:36 PM
Hi. I have one image that has to show up in a html page several times. To save time, I'd like to preload this image. As an example:

if (document.images) {
tester = new Image()
tester.onload=function() {cImg('good')}
tester.onerror=function() {cImg('bad')}
function cImg(typ) {
if (typ == 'bad') {alert('bad image') ; return}
document.images.main.src = tester.src

Problem, at least on my local html copy. When my IE6 loads the image, tester.src changes from "image.jpg" to "file:///C:/Inetpub/wwwroot/mas/image.jpg". document.images.main.src = tester.src", therefore, doesn't work. Question. After my onload, if I did document.images.main.src = "image.jpg", wouldn't another copy of "image.jpg" have to load?

I was thinking. Couldn't I set the object document.images.main to the object tester? If so, how?

This may be no big deal, but I'd like my offline copy of my web site to work like my online copy...Dennis