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

Q1187 When creating newLayer(), how can you give it a NAME or ID?

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

Q1187 When creating newLayer(), how can you give it a NAME or ID?

Try:

<html>

<head>
<script language="JavaScript"><!--
var myObjectLayer;

function createLayer(layerName,layerWidth) {
    if (document.layers) {
        myObjectLayer = new Layer(layerWidth);
        myObjectLayer.name = layerName;
    }
}

function loaded() {
    createLayer('myName',100);
    alert(myObjectLayer.name);
    alert(document.layers['myName'].name);
}
//--></script>
</head>

<body onLoad="loaded()">

</body>

</html>

On Netscape Navigator 4.5 on Linux, the setting of the layers name does not appear to work. Each time you create a layer Netscape gives it a name - for example: '__js_layer__10'. Each time you create another layer it appears as though the last number increase by one each time. It isn't (yet) possible to delete layers created this way - so treat this with caution, as you may find that the layers are not garbage collected once finished with, which might cause the browser to run out of memory.

Feedback on 'Q1187 When creating newLayer(), how can you give it a NAME or ID?'


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.