Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Swap image inside <div> NN errors

Status
Not open for further replies.

Izzo

Technical User
Feb 22, 2001
38
US
hi all,

Does anyone know why this script would not work in Netscape4.7 with the images in <div>'s?

[A portion of the <head> script]

over=new PreloadImages(20,'nav2_images/butovr','.gif')
norm=new PreloadImages(20,'nav2_images/but','.gif')

function Iswap(num){
if(document.images)
eval('document.images[&quot;norm'+num+'&quot;].src='+'over[num].src')
}
function Iback(num){
if(document.images)
eval('document.images[&quot;norm'+num+'&quot;].src='+'norm[num].src')
}

[The image script]

<td><a href=&quot;javascript:;&quot; onMouseOver=&quot;Iswap(1)&quot; onMouseOut=&quot;Iback(1)&quot;><img src=&quot;nav2_images/but1.gif&quot; name=&quot;norm1&quot; border=&quot;0&quot; width=&quot;155&quot; height=&quot;15&quot;></a></td>

Works in IE, but NN displays an error saying that the document.images has no properties. It is referring to eval line of the <head> script.

This script works as long as the images aren't inside of <div> tags but I need them there.

Thanks
Jason




 
Sounds like you need to read up the way NS works:

IE has a very 'flat' structure - you can reference any element however nested it is within other elements. Imagine a directory structure where you can reference any file by name without specifying a path!

Netscape has a 'tree' structure. Using the same analogy, you have to specify the whole path to the file.

The following example comes from my site:
OK - you have a set of nested divs:

<div id=&quot;myarea&quot; style=&quot;position: absolute; top:400; left:400; width: 111px; height: 128px; z-index:6&quot;>

<div id=&quot;whodiv&quot; style=&quot;position:absolute; left:20px; top:20px; z-index:5&quot;>
<IMG NAME=&quot;xx&quot; SRC=&quot;images/stephenf.gif&quot; WIDTH=&quot;109&quot; HEIGHT=&quot;126&quot; BORDER=0 ALT=&quot;&quot;>
</div>

<div id=&quot;star1&quot; style=&quot;position:absolute; left:20px; top:30px; z-index:9&quot;>
<IMG SRC=&quot;images/star.gif&quot; WIDTH=&quot;26&quot; HEIGHT=&quot;26&quot; BORDER=0>
</div>

</div>

To refer to the div &quot;star1&quot;

document.all(&quot;star1&quot;)

document.myarea.document.layers[&quot;star1&quot;]

Of course - if you want to do an image swap it gets silly:

function changepic(newsrc)
/* change the photo in the 'frame' */
{
if (document.all) {document.all.xx.src=newsrc;}
else {document.myarea.layers.whodiv.document.xx.src=newsrc;}
}

Have a look at the code for yourself.

Good luck.

Stephen
 
Thanks Stephen.

Yes I do need to read up on NS.
I went to your site and looked at the code.Works in IE but your page locks up in NS4.7 also.
I don't plan on nesting the div's like you have, but I guess the approach is basically the same.
What I am trying to do is just swap some images that sit in layers <div>tags.
I'll have to try your code again

If I get it working i will post the solution.

Thanks again, Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top