showhide ie5+ns4x =>works , ns6 dont !!

liunx

Guest
I try a lot of show-hide metods, but what work good<br />
in Ie5 and Ns4.7 ...dont work in Ns6...<br />
<br />
What is the corect sintax to make this function <br />
to work under these three navigators ?.<br />
<br />
This question is avaible too for slide options...<!--content-->Hi Sorin, welcome to htmlforums.<br />
Um, by looking at your spelling, I'd be more concerned that you have made a simple coding error. :). Actually, NS6 probably doesn't support it..haha. I'm sure kd in the client side scripting forum knows your answer though, he is right up on NS6 and is a wizard. Please post your current script that you have in there and what you would like it to do and I'm sure you'll get your answer.<!--content-->Here is a list of User Agents (browsers) that my technique supports (and should work on both PCs and Macs):<br />
IE4<br />
IE5<br />
IE5.5<br />
NS4.5, 4.6, 4.7, 4.76<br />
NS6.0<br />
<br />
Just copy the code below and save as a HTML page on your computer and view via your UA. It is a full walk-thru for hiding showing layers in the above UAs. Hope this helps<br />
<br />
<br />
<br />
<br />
======begin source - ================<br />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><br />
<br />
<html><br />
<head><br />
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=iso-8859-1"><br />
<META HTTP-EQUIV="Pragma" CONTENT="no-cache"><br />
<title>ULTRAPRISE.COM</title><br />
<LINK href=http://www.htmlforums.com/archive/index.php/"../somestyle.css" rel="stylesheet" type="text/css"> <br />
<title>MyServer.COM</title><br />
<br />
<style><br />
#sec1 {position: absolute; top: 175px; left:225px; visibility:hidden; z-index: 100; background-color:Khaki;}<br />
#sec2 {position: absolute; top: 175px; left:235px; visibility:hidden; z-index: 200; background-color:Gainsboro;}<br />
#sec3 {position: absolute; top: 175px; left:245px; visibility:hidden; z-index: 300; background-color:PaleTurquoise;}<br />
#sec4 {position: absolute; top: 175px; left:255px; visibility:hidden; z-index: 400; background-color:Bisque;}<br />
xmp {color:blue; background-color:PowderBlue;}<br />
</style><br />
<script><br />
//the next 2 lines are browser detection for 4.x user-agent DOMS<br />
ns4 = (document.layers) ? true:false //required for Functions to work<br />
ie4 = (document.all) ? true:false //required for Functions to work<br />
ng5 = (document.getElementById) ? true:false //required for Functions to work<br />
<br />
function hideSec() {<br />
if (ng5) document.getElementById('sec1').style.visibility = "hidden"<br />
else if (ns4) document.sec1.visibility = "hide"<br />
else if (ie4) sec1.style.visibility ="hidden"<br />
<br />
if (ng5) document.getElementById('sec2').style.visibility = "hidden"<br />
else if (ns4) document.sec2.visibility = "hide"<br />
else if (ie4) sec2.style.visibility ="hidden"<br />
<br />
if (ng5) document.getElementById('sec3').style.visibility = "hidden"<br />
else if (ns4) document.sec3.visibility = "hide"<br />
else if (ie4) sec3.style.visibility ="hidden"<br />
<br />
if (ng5) document.getElementById('sec4').style.visibility = "hidden"<br />
else if (ns4) document.sec4.visibility = "hide"<br />
else if (ie4) sec4.style.visibility ="hidden"<br />
}<br />
<br />
function showSec(n) {<br />
hideSec();<br />
if (ng5) document.getElementById('sec' + n).style.visibility = "visible";<br />
else if (ns4) document.layers["sec" + n].visibility = "show";<br />
else if (ie4) document.all["sec" + n].style.visibility = "visible";<br />
}<br />
<br />
function showAllSec(n) {<br />
if (ng5) document.getElementById('sec' + n).style.visibility = "visible";<br />
else if (ns4) document.layers["sec" + n].visibility = "show";<br />
else if (ie4) document.all["sec" + n].style.visibility = "visible";<br />
}<br />
<br />
</script><br />
<br />
</head><br />
<br />
<body bgcolor="#ffffff"><br />
<h1 class="grouphead">*Layer Hiding and Showing</h1><br />
<b>CROSS-BROWSER w/ FULL 4.X, 5.X, and 6.x SUPPORT!!</b><BR><br />
This is a more complex method of working with multiple layers. Attention will need to made to the layer naming convention, hide sequences, and Javascript Function design (what is the specific Function doing?).<br />
<br><br />
<br><br />
<br />
This method of hiding and showing layers is designed to be used with layers that require related layers to interact with each other. For demonstration purposes, each layer here has been offset 10 pixels to the left from the previous layer and the layer z-index is increased.<br />
<br />
<br />
<br><br />
<br><br />
<a href=http://www.htmlforums.com/archive/index.php/"#" onClick="showAllSec(1),showAllSec(2),showAllSec(3),showAllSec(4)">Show All</a><br><br />
<a href=http://www.htmlforums.com/archive/index.php/"#" onClick="showSec(1)">Show Layer 1</a>, Hide 2, 3, and 4 <br><br />
<a href=http://www.htmlforums.com/archive/index.php/"#" onClick="showSec(3)">Show Layer 3</a>, Hide 1, 2 and 4<br><br />
<a href=http://www.htmlforums.com/archive/index.php/"#" onClick="showSec(4)">Show Layer 4</a>, Hide 1, 2 and 3<br><br />
<br><br><br />
There are several parts to making this work:<br />
<ol><br />
<li><b>DIV/SPAN defined style</b><br><br />
This is defined within the embedded style portion at the top of the page. Each layer <b>MUST</b> have the same prefix (in this case: "<b>sec</b>") followed by a sequential number. <br />
<xmp><br />
<style><br />
#sec1 {position: absolute; top: 175px; left:225px; visibility:hidden; z-index: 100; background-color:Khaki;}<br />
#sec2 {position: absolute; top: 175px; left:235px; visibility:hidden; z-index: 200; background-color:Gainsboro;}<br />
#sec3 {position: absolute; top: 175px; left:245px; visibility:hidden; z-index: 300; background-color:PaleTurquoise;}<br />
#sec4 {position: absolute; top: 175px; left:255px; visibility:hidden; z-index: 400; background-color:Bisque;}<br />
</style><br />
</xmp><br />
<br />
<li><b>Javascript - Part 1</b><br><br />
ALL JavaScript <b>MUST</b> be placed in the <HEAD> section of the page. <br><br />
This is the browser detection routine that sets-up the DOM. <br />
<xmp><br />
<script><br />
ns4 = (document.layers) ? true:false<br />
ie4 = (document.all) ? true:false <br />
ng5 = (document.getElementById) ? true:false <br />
</script><br />
</xmp><br />
<br />
<li><b>Javascript - Part 2</b><br><br />
The code to HIDE a set of layers. You will need to repeat each IF/ELSE for each layer, incrementing the number as you proceed.<br />
<xmp><br />
function hideSec() {<br />
if (ng5) document.getElementById('sec1').style.visibility = "hidden"<br />
else if (ns4) document.sec1.visibility = "hide"<br />
else if (ie4) sec1.style.visibility ="hidden"<br />
<br />
if (ng5) document.getElementById('sec2').style.visibility = "hidden"<br />
else if (ns4) document.sec2.visibility = "hide"<br />
else if (ie4) sec2.style.visibility ="hidden"<br />
}<br />
</xmp><br />
<br />
<li><b>Javascript - Part 3</b><br><br />
The code to DISPLAY a single layer and HIDE all other layers. Note the "HIDE" function is called first, and it also does NOT have a number assigned to it. This "hides" all layers globally (of the particular suffix set).<br />
<xmp><br />
function showSec(n) {<br />
hideSec();<br />
if (ng5) document.getElementById('sec' + n).style.visibility = "visible";<br />
else if (ns4) document.layers["sec" + n].visibility = "show";<br />
else if (ie4) document.all["sec" + n].style.visibility = "visible";<br />
}<br />
</xmp><br />
<br />
<li><b>An Event</b><br><br />
One of various events, onClick, OnMouseover, OnMouseOut etc, to call the pert function. <br><br />
Please note that the text (layer name) after the function name must be within parenthesis.<br />
<xmp><br />
<a href=http://www.htmlforums.com/archive/index.php/"#" onMouseOver="showSec(2)">mouseover to display the 2nd layer</a><br />
</xmp><br />
</ol><br />
<br />
<br />
<br />
<br />
<br><br />
<br><br />
<br />
<div id="sec1"><br />
This is layer ID <b>sec1</b><br><br />
This is the lowest layer in the z-index order.<br />
</div><br />
<br />
<div id="sec2"><br />
This is layer ID <b>sec2</b><br><br />
This is the 2nd lowest layer in the z-index order.<br />
</div><br />
<br />
<div id="sec3"><br />
This is layer ID <b>sec3</b><br><br />
This is the 2nd highest layer in the z-index order.<br />
</div><br />
<br />
<div id="sec4"><br />
This is layer ID <b>sec4</b><br><br />
This is the highest layer in the z-index order.<br />
</div><br />
<br />
<br />
<br />
<br />
</body><br />
</html><br />
<br />
<br />
[Edited by Marlboro on 02-19-2001 at 03:12 PM]<!--content-->
 
Back
Top