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

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

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

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?'

©2018 Martin Webb