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

Q1063 How can I find out the width and height of a layer?

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

Q1063 How can I find out the width and height of a layer?

The following should work on Netscape Navigator 4+ and Internet Explorer 4+:

<body onLoad="textWidth()">

<script language="JavaScript"><!--
function textWidth() {
    if (document.layers)
        alert('width = ' + document.layers['myId'].document.width + ' height = ' + document.layers['myId'].document.height);
    else if (document.all)
        alert('width = ' + document.all['myId'].clientWidth + ' height = ' +  document.all['myId'].clientHeight);
}
//--></script>

<div id="myId" style="position:absolute;">
How wide<BR>
and how<BR>
high is<BR>
this <BR>
layer<BR>
</div>

Conor McMenamin writes:

People may find this more useful in Internet Explorer 4+, as IE4 thinks all divs are the width of the window unless told otherwise. The 1px can expand but the full window width will not contract:

<body onLoad="textWidth()">

<script language="JavaScript"><!--
function textWidth() {
    if (document.layers)
        alert('width = ' + document.layers['myId'].document.width + ' height = ' + document.layers['myId'].document.height);
    else if (document.all)
        alert('width = ' + document.all['myId'].clientWidth + ' height = ' +  document.all['myId'].clientHeight);
}
//--></script>

<div id="myId" style="position:absolute; width:1px;">
How wide<BR>
and how<BR>
high is<BR>
this <BR>
layer<BR>
</div>

Feedback on 'Q1063 How can I find out the width and height of a layer?'


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.