layer problems

liunx

Guest
Hi All,,<br />
can anyone help me, I have a web page with several layers on it which all overlay each other as I only want any one layer to be viewable! - I have this working using the following code:<br />
<br />
<script language="javascript"><br />
// Courtesy of SimplytheBest.net (<!-- m --><a class="postlink" href="http://simplythebest.net/info/dhtml_scripts.html">http://simplythebest.net/info/dhtml_scripts.html</a><!-- m -->)<br />
<!--<br />
if (document.layers) {<br />
visible = 'show';<br />
hidden = 'hide';n=1;ie=0;<br />
} else if (document.all) {<br />
visible = 'visible';<br />
hidden = 'hidden';n=0;ie=1;<br />
}<br />
function showDivs (divName,divNumber) {<br />
var divsUsed = 3; // this is the number of divs we have in the document for each element<br />
if (navigator.appName.indexOf ("Microsoft") == 0 || navigator.appName.indexOf ("Netscape") == 0) {<br />
if (parseInt (navigator.appVersion) >= 4) {<br />
<br />
var cnt = 0;<br />
for (cnt = 1; cnt <= divsUsed; cnt++) {<br />
var divCheck = divName + cnt;<br />
var divShow = divName + divNumber;<br />
if (ie) {<br />
if (divCheck == divShow) <br />
document.all(divShow).style.visibility = visible;<br />
else <br />
document.all(divCheck).style.visibility = hidden;<br />
}<br />
if (n) {<br />
if (divCheck == divShow) <br />
document.layers[divShow].visibility = visible;<br />
else <br />
document.layers[divCheck].visibility = hidden;<br />
} <br />
}<br />
}<br />
}<br />
}<br />
var ver = parseFloat (navigator.appVersion);<br />
if ((navigator.appName.indexOf ("Netscape") == 0) && (ver >= 4)) {<br />
} else if ((navigator.appName.indexOf ("Mozilla") == 0) && (ver >= 5)) {<br />
} else if ((navigator.appName.indexOf ("Microsoft") == 0) && (ver >= 4)) {<br />
} else {<br />
location="oldbrowser.html";<br />
}<br />
// --><br />
</script><br />
<br />
This works fine except that some of the layers are considerably longer than others and when the layer changes the user is looking at a blank web page!<br />
<br />
Is it possible to change the layer and also jump back up to the top of the page (posssibly to a pre-defined anchor)?<!--content-->I don't know, did you try putting an internal anchor in each layer and seeing what happens?<!--content-->I tried in one of my test layers, but it seems that I can only run one event using the onclick function!<br />
<br />
Is it actually possible to do the following:<br />
<br />
<a class="roll2" href=http://www.htmlforums.com/archive/index.php/"#" onclick="showDivs('layer_',1); return false;"b>Link Text</b></a><br><br />
<br />
And run the following off one onclick procedure?<br />
<br />
onclick="document.location='#top';"<br />
<br />
They both work on their own (off two seperate hyperlinks) but I'd like to process both off one click!<!--content-->Hi Deker,<br />
<br />
Please don't take this personally. But, that simply the best code is atrocious! (I'm in a semi-bad mode, so please excuse me; if not, I don't really care :)<br />
<br />
1) it only addresses NN4 (document.layers) & IE4+ (document.all); NN6 is accessed through "document.getElementById"<br />
2) it is generally a bad idea to check for name when checking for browsers -- eg. only some AOL browsers have 'msie' in them, but all of them have document.all and anything version 5+ has document.getElementByID<br />
<br />
because you didn't post any of your own code (neither javascript nor HTML) I have to be general:<br />
<br />
let's presume you have a global variable called numofDivs, a bunch of divs with the names/ids "div0, div1, etc" and a function like this (where 'divID' is the specific ID for the div that needs to be visible):<br />
<br />
function changeVis(divID)<br />
{<br />
for (i = 0; i < numOfDivs; i++)<br />
{<br />
divStyle = (document.layers) ? document.layers['div' + i] : (document.all) ? document.all['div' + i].style : document.getElementById('div' + i).style ;<br />
<br />
divStyle.visibility = 'hidden';<br />
}<br />
divStyle = (document.layers) ? document.layers[divID] : (document.all) ? document.all[divID].style : document.getElementById(divID).style ;<br />
divStyle.visibility = 'visible'<br />
}<br />
<br />
of course, your own code would be better to work from. Or, you can see the dHTML scripts/tutorials at my site -- even if they're not what you want -- you should learn something from them.<br />
<br />
Vinny<!--content-->Thanks for the help, I'll check your web site out for advice<!--content-->
 
Back
Top