[thelist] Re: Re: Re: Accessing layers in Javascript

Peter-Paul Koch gassinaumasis at hotmail.com
Wed Jan 30 16:50:01 CST 2002



>For lack of A) insight on how to fork the code for the browser without
>repeating, and B) knowledge of how to get the layer ID string in >Netscape
>4.x, I'd try this:

Annotated with object detection and NN4 compatibility:

><SCRIPT LANGUAGE="JavaScript1.2"><!--
>var counter = 0;
>

if (document.getElementsByTagName) {

>var Layer = document.getElementsByTagName("DIV");
>	for (var i = 0; i < Layer.length; i++)
>		if (Layer[i].getAttribute('id').indexOf("menu") != -1)
>			counter++;

} else if (document.all) {

>var Layer = document.all.tags("DIV");
>	for (var i = 0; i < Layer.length; i++)
>		if (Layer[i].id.indexOf("menu") != -1)
>			counter++;

} else if (document.layers) {
var Layer = document.layers;
       for (var i=0;i<Layer.length;i++)
		if (Layer[i].id.indexOf("menu") != -1)
			counter++;

  else {
    // no go
  }

>//--></SCRIPT>

Note that NN4 compatibility may not be perfect, it works only on layers (=
DIVs with a position: absolute | relative declared in the style sheets OR
layer tags) that are direct children of the BODY tag. Nested layers aren't
counted.
ppk

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com




More information about the thelist mailing list