Javascript Preload Image in IE
I was intend to make a button that swap an image, the following is the javascript for it, but in IE, the images doesn't change, why?
thank you all for your help in advance!
//==================
var img1, img2;
//preload Images
function preloadImage(localhost, WaitImage, BlankImage)
{
img1 = new Image();
img2 = new Image();
img1.src = localhost + '/images/' + BlankImage;
img2.src = localhost + '/images/' + WaitImage;
}
//For swaping image
function SwapImage(localhost,imagename)
{
if(document.images)
{
for(i = 0; i < document.images.length; i++)
{
if(imagename == 'img1.gif')
{
document.images[i].src = img2.src;
}
else
{
document.images[i].src = img1.src;
}
}
}
}
<BODY onload=preloadImage('somehost','img1.gif','img2.gif')>
<INPUT type=BUTTON onClick=SwapImag(somehost,img1.gif)>
</BODY>