PDA

View Full Version : Simple Netscape 4 issue


sue_hernandez
07-25-2005, 07:36 PM
I have what I think should be a very simple question for Netscape 4.79. I am simply tring to switch an image source from one image to another. IE works fine, but I can't seem to find code samples after browsing through Google.

My code is as follows:

var ns4=(document.layers)?true:false;

function HideContent()
{
if(ns4)
{
document.layers["imgContent"].src = "images/nav1.gif";
document.layers["imgContentButton"].src = "images/nav2-over.gif";
document.layers["imgHome"].src = "images/nav_home.gif";
}
else
{
if(document.getElementById)
{
document.getElementById("imgContent").src = "images/nav1.gif";
document.getElementById("imgContentButton").src = "images/nav2-over.gif";
document.getElementById("imgHome").src = "images/nav_home.gif";
}
}
}

I know I've searched for this before, I don't know why I can't find it now. The problem seems to be accessing the image element, although I've tried to put style="position: relative" and that didn't help any. Should I just put div's around every one of the images and hide/show that way? Yuck.

Any tips would be greatly appreciated.

Thanks
Sue

_Aerospace_Eng_
07-25-2005, 07:41 PM
Can we see your html as well? I don't code for NS4 but your problem could be something as simple where you used an id but you didn't use a name as well.

COBOLdinosaur
07-25-2005, 07:58 PM
I don't why anyone is still supporting Netscrap 4, but inany case this is the way to have to do it for the relic.

document.images['imgHome].src= etc


That same code will still work for modern browsers like FF and IE6 because the images collection is still part of the DOM. However you have to use a name attribute on the image:

<img src="blah.gif" name="imgHome">

sue_hernandez
07-25-2005, 08:16 PM
Aerospace and Dinosaur, thanks for the replies. I forgot to try the "name" tag, and I forgot about the document.images collection. I was getting div's to work by using the document.layers collection. Have to do images differently.

Unfortunately, we have to support all the way down to NS 4.79 due to the audience we cater to. Our web statistics show that a surprising amount of people, if still a very small percentage, do use very old browsers.

Thanks for the help.
Sue