Equivalent of Measurestring in javascript?

Discussion in 'Javascript' started by intrepid_dw@hotmail.com, Oct 24, 2006.

  1. Guest

    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
     
    , Oct 24, 2006
    #1
    1. Advertising

  2. Evertjan. Guest

    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>

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Oct 24, 2006
    #2
    1. Advertising

  3. Guest

    Evertjan,

    Thanks very much! I appreciate your effort.

    -intrepid

    Evertjan. wrote:
    > 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>
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)
     
    , Oct 25, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Erik Veldkamp
    Replies:
    2
    Views:
    22,039
    rogachez
    Jun 18, 2010
  2. Jim Ciotuszynski

    Javascript:return vbscript equivalent

    Jim Ciotuszynski, Jul 6, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    6,671
    nescafe
    Sep 15, 2011
  3. Michael Foord

    Equivalent of Javascript Bitwise Operators

    Michael Foord, Oct 27, 2004, in forum: Python
    Replies:
    2
    Views:
    609
    Bengt Richter
    Oct 28, 2004
  4. Replies:
    7
    Views:
    393
  5. teo
    Replies:
    2
    Views:
    545
Loading...

Share This Page