Equivalent of Measurestring in javascript?

I

intrepid_dw

All;

As the subject implies, I'm wondering if there is anything resembling a
Javascript equivalent of a MeasureString method?

I am dynamically constructing a dialog box with a user-specified
message, and I might need to resize the box based on the length of the
message, but I've not found anything that might suggest how I can
determine the length of a string rendered in the current browser
window's font.

Thanks for any help.

-intrepid
 
E

Evertjan.

wrote on 24 okt 2006 in comp.lang.javascript:
As the subject implies, I'm wondering if there is anything resembling a
Javascript equivalent of a MeasureString method?

MeasureString method?

===================================

<span id='q'>zzz</span>

<script type='text/javascript'>
var q = document.getElementById('q')
s = 'the quick brown fox'
q.innerHTML = s
alert(q.offsetWidth)
s = 'the quick brown fox jumps over the'
q.innerHTML = s
alert(q.offsetWidth)
q.innerHTML = ''
alert(q.offsetWidth)
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top