Forum Moderators: open

Message Too Old, No Replies

Image swap script not working for all users

         

tintin99

1:11 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



I'm using this script to change the main image on a page when a thumbnail is clicked. It works fine on some pc's but not on others even though they're using the same browser (IE6). In cases where it doesn't work the main default image goes blank but the new image doesn't appear. Any ideas? I'm really stuck on this one.

----------------------------------
<head>

<script type="text/javascript">
<!--
if (document.images)
{
image1= new Image(); image1.src="../images/floral/pinkandwhiteroses.jpg";
image2= new Image(); image2.src="../images/floral/greenandwhite.jpg";
image3= new Image(); image3.src="../images/floral/whitelisianthus.jpg";
image4= new Image();
}

function change(picName,imgName)
{
if (document.images)
{
imgOn=eval(imgName + ".src");
document[picName].src= imgOn;
}
}
//-->
</script>
</head>

<body>

<table id="imageTable">
<tr>
<td rowspan="5"><img src="../images/floral/floral2_2.jpg" name="mainImg" id="mainImg" alt="" width="330" height="330" /></td>
<td colspan="3" class="headerCell"><h3>Floral Still Life </h3></td>
</tr>
<tr>
<td class="thumbnailCell"><a href="javascript:;" onclick="change('mainImg','image1')"><img src="../images/floral/pinkandwhiteroses_s.jpg" alt="" width="60" height="60" /></a></td>
<td class="thumbnailCell"><a href="javascript:;" onclick="change('mainImg','image2')"><img src="../images/floral/greenandwhite_s.jpg" alt="" width="60" height="60" /></a></td>
<td class="thumbnailCell"><a href="javascript:;" onclick="change('mainImg','image3')"><img src="../images/floral/whitelisianthus_s.jpg" alt="" width="60" height="60" /></a></td>
</tr>

etc

King_Kong

4:56 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



probably not showing because they haven't loaded yet. (can't see any obvious errors with your code except the extra image4 bit).

Try pre-caching them by loading them in a previous page, or disabling the roll-over functionality until the whole page has loaded.

tintin99

5:06 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



Thanks for the reply King Kong. I thought that image loading time might be the problem too so I asked one guy to leave the page on the screen for 5 minutes before trying it. It still didn't work.

Anyway it's reassuring you can't see any errors in the script.

By the way the extra 'image4' bit was just my bad copying and pasting...there's actually 12 images on the page but I didn't want to post the whole caboodle.