By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,568 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,568 IT Pros & Developers. It's quick & easy.

show/hide layers onLoad

P: n/a
Hi

I'm looking for a javascript with the following operation:

if history.length <=2
show "layer1" and hide "layer2"

else
hide "layer1' and show "layer2"

Notes
"layer1" and "layer2" are the IDs of two layers
this should be in a function, in order to call it with onLoad

Can someone help me please?

--
Merlin dying to the Lady of the Lake:
"We lived our lives with passion and devotion"
--
Please remove slashes to contact me
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

geotso <kata/ye/xi@yahoo.gr> wrote in message news
:cs**********@usenet.otenet.gr...
Hi

I'm looking for a javascript with the following operation:

if history.length <=2
show "layer1" and hide "layer2"

else
hide "layer1' and show "layer2"

Notes
"layer1" and "layer2" are the IDs of two layers
this should be in a function, in order to call it with onLoad

Can someone help me please?


history.length is treated inconsistently across browsers.

Assuming both layers are initially styled as hidden.

Call with: <body onload='showLayer("layer1","layer2")'>

function showLayer(L1, L2)
{
var ref=null;
if( document.getElementById && (ref=document.get
ElementById(history.length<=2 ? L1 : L2)) )
ref.style.visibility='visible';
}

--
S.C.

Jul 23 '05 #2

P: n/a
Stephen Chalmers wrote:
geotso <kata/ye/xi@yahoo.gr> wrote in message news
cs**********@usenet.otenet.gr...
Hi

I'm looking for a javascript with the following operation:

if history.length <=2
show "layer1" and hide "layer2"

else
hide "layer1' and show "layer2"

Notes
"layer1" and "layer2" are the IDs of two layers
this should be in a function, in order to call it with onLoad

Can someone help me please?


history.length is treated inconsistently across browsers.

Assuming both layers are initially styled as hidden.

Call with: <body onload='showLayer("layer1","layer2")'>

function showLayer(L1, L2)
{
var ref=null;
if( document.getElementById && (ref=document.get
ElementById(history.length<=2 ? L1 : L2)) )
ref.style.visibility='visible';
}


It works like a charm!

(a small change, just for the records:
I've used style="display:none" and then .style.display=''; instead of
style="visibility:hidden" and .style.visibility='visible'.
This way, I prevent browser's window from displaying the vertical scrollbar
if anyone of the layers is too short to need it).

Thank you very much!!
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.