show/hide layers onLoad

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • geotso

    show/hide layers onLoad

    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
  • Stephen Chalmers

    #2
    Re: show/hide layers onLoad


    geotso <kata/ye/xi@yahoo.gr> wrote in message news
    :cs19hd$eto$1@u senet.otenet.gr ...[color=blue]
    > 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?[/color]

    history.length is treated inconsistently across browsers.

    Assuming both layers are initially styled as hidden.

    Call with: <body onload='showLay er("layer1","la yer2")'>

    function showLayer(L1, L2)
    {
    var ref=null;
    if( document.getEle mentById && (ref=document.g et
    ElementById(his tory.length<=2 ? L1 : L2)) )
    ref.style.visib ility='visible' ;
    }

    --
    S.C.



    Comment

    • geotso

      #3
      Re: show/hide layers onLoad

      Stephen Chalmers wrote:[color=blue]
      > geotso <kata/ye/xi@yahoo.gr> wrote in message news[color=green]
      >> cs19hd$eto$1@us enet.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?[/color]
      >
      > history.length is treated inconsistently across browsers.
      >
      > Assuming both layers are initially styled as hidden.
      >
      > Call with: <body onload='showLay er("layer1","la yer2")'>
      >
      > function showLayer(L1, L2)
      > {
      > var ref=null;
      > if( document.getEle mentById && (ref=document.g et
      > ElementById(his tory.length<=2 ? L1 : L2)) )
      > ref.style.visib ility='visible' ;
      > }[/color]

      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="visibili ty:hidden" and .style.visibili ty='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!!


      Comment

      Working...