Results 1 to 3 of 3

Thread: Javascript Preload Image in IE

  1. #1
    graphite
    Guest

    Talking 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>

  2. #2
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    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

  3. #3
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    try changing this line:

    <INPUT type=BUTTON onClick=SwapImag(somehost,img1.gif)>


    to this:

    <INPUT type=BUTTON onClick=SwapImag(somehost,' img1.gif ')>
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width