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

Mark Howells mark at mark.ac
Wed Jan 30 18:27:01 CST 2002


On Wednesday, January 30, 2002, at 11:51  PM, Peter-Paul Koch wrote:

>> 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:
>
> if (document.getElementsByTagName) {
> } else if (document.all) {
> } else if (document.layers) {
>  else {
>  }
>

> 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

Thanks for this alternative suggestion, but I'm already using the
document.layers and document.all arrays to cover all JS capable browsers
prior to those which understand document.getElementsByTagName. The
restriction to only analyzing div tags with
document.getElementsByTagName is that I can't loop through an array of
layer objects and so I have to assume that all of the layers (absolutely
positioned elements) are going to be div tags.

Ben's suggestion -

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

- works well in IE, I'll have to check it in NN6 in the morning.

Regards
Mark Howells
<http://www.mark.ac/evl>




More information about the thelist mailing list