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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toggle Javascript

Status
Not open for further replies.

DigitalBoy

Programmer
Oct 11, 2000
87
US
I have the follow code in an html page:

<html>
<script language=&quot;Javascript&quot;>
function toggle(object)
{
var tObj = document.all[object];

if (tObj.style.visibility == &quot;hidden&quot;)
tObj.style.visibility = 'visible';
else
tObj.style.visibility = 'hidden';
}
</script>

<body>
<img id=&quot;rate&quot; src=&quot;img.bmp&quot;></img><a href=&quot;javascript:toggle('rate');&quot;>NR</a>
</body>
</html>

The code works fine in IE, but not in NS. What changes do I have to make to ensure that this code works in NS? Thanks in advance.

- DB

dgtlby@excite.com
Administrator

UBB Developers Network

 
ugh the thread thing is broke, try this instead, change your tobj definition to:


var tObj = (document.all)?document.all[object]:document.getElementById(object);


that will make it work in IE4+ and Netscape 6. in netscape 4.x you can only toggle visibility of layers. that is achieved like so:

document.layers.layername.visibility='hide'

However, I do not suggest supporting NS4.X anymore. A small percentage (<10%) are using this browser. If we (developers / designers) continue to support this, our clients / bosses will forever expect NS4 support. This forces our code to be clunky and inefficent. It also prevents us from using the latest/emerging technology (like DOM methods!). forget NS4. I only offer support for IE5+/NS6+ and some opera 5. jared@aauser.com -
 
Just to clarify, I'm developing for Interactive TV and the current javascript spec doesn't work with the IE code. Unfortunately, I really have no choice. Specific browsers are chosen for set top boxes and we must use those browsers.

- DB

dgtlby@excite.com
Administrator

UBB Developers Network

 
ah... excuse set top boxes from my rant :)

document.layers.layername.visibility='hide'

should work with a NS4.x compatible browser, but it only works on layers jared@aauser.com -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top