Click to See Complete Forum and Search --> : document.layer for netscape 7x


scialom
01-30-2003, 05:34 AM
Hi

I have this code:
function Is ()
{ var agt=navigator.userAgent.toLowerCase();
//alert (agt);
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);

this.nav = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
&& (agt.indexOf('compatible') == -1)));
this.nav2 = (this.nav && (this.major == 2));
this.nav3 = (this.nav && (this.major == 3));
this.nav4 = (this.nav && (this.major == 4));
this.nav5 = (this.nav && (this.major == 5));

this.vms = (agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1);
}
function toggleT(_w,_h) {
var is = new Is();

if (is.nav) { // is NS?

if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
}
else { // is IE
//alert ("a");
if (_h=='s') eval("document.all."+_w+".style.visibility='visible';");
if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';");
}


}

works good on ie, but not on netscape 7.0
any idea?
Assaf

khalidali63
01-30-2003, 06:22 AM
for NS6+ you can refre any object by using DOM methods.
so in teh the above case you will have
another if statement that will make sure that browser is NS6+/mozilla1+ broser
e.g
else if(ns6{ //
if (_h=='s') eval("document.getElementById(_w).style.visibility='visible';");
if (_h=='h') eval("document.getElementById(_w).style.visibility='hidden';");
}

This should do it for you..

cheers

Khalid

gil davis
01-30-2003, 06:40 AM
NS 7 does not support the document.layers array. As khalidali63 pointed out, you can use document.getElementById() to get the object, but that just scratches the surface. You probably have lots more places in your code that were designed for NS 4 where NS 7 will fail to work. However, your function toggleT() can be modified thus:

function toggleT(_w,_h) {
var vis = (_h == "s") ? "visible" : "hidden";
if (document.layers) // is NS 4?
{document.layers[_w].visibility = (h == "s") ? "show" : "hide";}
else
{if (document.getElementById) // W3C DOM
{document.getElementById(_w).style.visibility = vis;}
else // old IE
{document.all[_w].style.visibility = vis;}
}
}