Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | DHTML | Q1185 [ previous next ]

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

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.