Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1185 Why can't I access an image within a layer nested within a layer?

You are here: irt.org | FAQ | DHTML | Q1185 [ previous next ]

In theory it should be possible to access the image within a nested layer with:

document.layers[0].document.layers[0].document.images[0].src

However this doesn't seem to work once you specifiy a style position of absolute for the nested layer.

This would appear to be a bug.

If you don't specify absolute positioning then it works:

<body onLoad="loaded()">

<ilayer id="top">
    <layer id="nested">
    <img src="image.gif" name="myImage">
    </layer>
</ilayer>

<script language="JavaScript"><!--
function loaded() {
    alert(document.layers['top'].document.layers['nested'].document.images['myImage'].src);
}
//--></script>

Alternatively - you can add the layer in afterwards:

<body onLoad="addLayers()">

<ilayer id="top">
</ilayer>

<script language="JavaScript"><!--
function addLayers() {

    myLayer = new Layer(100,document.layers['top']);

    document.layers['top'].document.layers[0].document.open();
    document.layers['top'].document.layers[0].document.write('<img src="image.gif" name="myImage">');
    document.layers['top'].document.layers[0].document.close();


    alert(document.layers['top'].document.layers[0].document.images['myImage'].src);
}
//--></script>

©2018 Martin Webb