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

hiding layers on a page

Status
Not open for further replies.

scroce

MIS
Nov 30, 2000
780
US
I wrote a function which works in IE5, but not in netscape 4x - can anybody tell me why this is so? here's the code:
Code:
var currentLayer = "AboutUs";

function turnOn(newLayer) {
  if (currentLayer != newLayer) {
    var thisLayer = document.getElementById(newLayer);
    thisLayer.style.visibility = "visible";
    var oldLayer = document.getElementById(currentLayer);
    oldLayer.style.visibility = "hidden";
    
    currentLayer = newLayer;
    }

}

It's called by the following html:

Code:
<a href=&quot;javascript:turnOn('AboutUs');&quot;>About Us</a>
<a href=&quot;javascript:turnOn('Contact');&quot;>Contacts</a>

Q: Why is my computer doing that?
A: Random Perversity of Inanimate
Objects
 
Not sure why Netscape doesn't support it - I can't be bothered looking it up either - probably an unsupported method.

try putting the following two sections of HTML in somewhere:

<a href=&quot;javascript:turnOn('AboutUs');&quot;>About Us</a>
<a href=&quot;javascript:turnOn('Contact');&quot;>Contact</a>

- to call the appropriate script and input the page name var.

and

<a id=&quot;area1&quot;></a>

- to give a named object holder. This can go anywhere in the doc.

the JavaScript could be something like:

currentlayer = &quot;AboutUs&quot;;
function turnOn(newlayer)
{
{
if (newlayer == currentlayer)
{
alert('This is what you are already looking at.');
return;
}
} //I like using a lot of these to make my code more readable and my if statements well separated.
{
if (newlayer == &quot;AboutUs&quot;)
{
myhtml = (&quot;<div id='layer1' style='position:absolute; width:173px; height:88px; z-index:2; left: 50px; top: 50px'><p>Some text with single char ignores like Andy/'s stuff etc...</p><!--put whatever html you want visible here--></div>&quot;); //the div layer allows you to position the content wherever you like. To see more about the use of the div layer in presenting content, you might want a look at my web site. and save the page. The .js files control the animations and the page is simply a long list of object holders.
area1.innerHTML = myhtml;
currentlayer = &quot;AboutUs&quot;;
return;
}
}
{
if (newlayer == &quot;Contact&quot;)
{
myhtml = (&quot;<div id='layer1' style='position:absolute; width:173px; height:88px; z-index:2; left: 50px; top: 50px'><p>Some

other text with single char ignores like Andy/'s stuff etc...</p><!--put whatever html you want visible here--></div>&quot;);
area1.innerHTML = myhtml;
currentlayer = &quot;Contact&quot;;
return;
}
}
return;
}

I suppose I'm not actually answering your question but maybe what you are trying to achieve can be obtained by using the above.

Andy ;-)
 
If I'm correct, Netscape is probably telling you that layer.style has no properties. I think 4.7 and prior did things a little differently. Dunno if this is a DOM/non-DOM issue, but try layer.style=&quot;visibility: hidden;&quot;;
 
tried the solution layer.style=&quot;visibility: hidden;&quot;;

didn't seem to work. arrgh. very frustrating. Q: Why is my computer doing that?
A: Random Perversity of Inanimate
Objects
 
answer - I wrote really bad coding here, and i'll clean it up later, but this is essentially it - The essential problem was the syntax which NN4.76 interprets differently from IE5 - so you have to write in some browser detection code.
I'll hi-lite the main syntax differences in red.

function turnMeOn(layerName) {

var browser = navigator.appName
var browserVer = navigator.appVersion
var firstLayer = &quot;AboutUs&quot;
var secondLayer = &quot;Contact&quot;


//document.write(&quot;You are browsing this site with: &quot;+ navigator.appName)
//window.alert(&quot;You are browsing this site with: &quot;+ browser);
//document.write(&quot;and you have version: &quot;+navigator.appVersion )
//window.alert(&quot;and you have version: &quot;+ browserVer );
if (browser == &quot;Netscape&quot;) {
//window.alert (&quot;Netscape!&quot;);
if (layerName==firstLayer) {

document.layers[firstLayer].visibility = &quot;visible&quot;;
document.layers[secondLayer].visibility= &quot;hidden&quot;;

}else if (layerName==secondLayer) {
document.layers[secondLayer].visibility = &quot;visible&quot;;
document.layers[firstLayer].visibility= &quot;hidden&quot;;
}
} else if (browser = &quot;Microsoft Internet Explorer&quot;) {
//window.alert (&quot;IE!&quot;);
if (layerName==firstLayer){
document.getElementById (firstLayer).style.visibility = &quot;visible&quot;;
document.getElementById (secondLayer).style .visibility = &quot;hidden&quot;;

} else if (layerName==secondLayer) {
document.getElementById (secondLayer).style.visibility = &quot;visible&quot;;
document.getElementById (firstLayer).style .visibility = &quot;hidden&quot;;
}
}
} Q: Why is my computer doing that?
A: Random Perversity of Inanimate
Objects
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top