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

Q1035 How can I find out the width of text rendered by the document?

You are here: irt.org | FAQ | DHTML | Q1035 [ 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['nn'].document.width);
    else if (document.all)
        alert('width = ' + document.all['msie'].clientWidth);
}
//--></script>

<div id="msie">
<layer id="nn">
How long is this string?
</layer>
</div>

Feedback on 'Q1035 How can I find out the width of text rendered by the document?'

©2018 Martin Webb