|
-
Sep 20th, 2001, 04:45 PM
#1
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>
-
Sep 22nd, 2001, 05:47 PM
#2
Fanatic Member
i wouldnt have a clue off-hand cos i dont a huge amount of javascript. but i think dreamweaver had the swapimage funcion in it somewhere so my advice would be to download it and copy the source it generetes. not the best solution but a working one 
hope i was of help. michael
-
Sep 26th, 2001, 07:52 PM
#3
Fanatic Member
try changing this line:
<INPUT type=BUTTON onClick=SwapImag(somehost,img1.gif)>
to this:
<INPUT type=BUTTON onClick=SwapImag(somehost,' img1.gif ')>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|