Width of a String

Discussion in 'Javascript' started by Afshin, Dec 8, 2003.

  1. Afshin

    Afshin Guest

    Hi,

    I am trying to create a very long dynamic document with fixed width
    for the cells of my table iin HTML, I need to truncate some of the
    information that I display to fit in the table.

    As the document is very long I can not use the offsetwidth
    functionality of the cell because then the user will see the
    information being truncated, which is not desireable, I was wondering
    if there is any way of calculating the width of the text displayed in
    the "risky" rows on the fly before the whole document gets rendered.

    I tried to display the information in the row and then try to truncate
    it right away after using the offsetwidth to see the width of the text
    in pixel, but this is not working as the offsetwidth needs the whole
    document to be rendered before being able to calculate the exact
    value.

    If anybody has any idea of how to do this on the fly I would
    appreciate yor help.

    Thanks

    Afshin
    Afshin, Dec 8, 2003
    #1
    1. Advertising

  2. Afshin

    Mike Guest

    Try doing something clever like setting the visibility of the table to
    hidden, then calculate your offsetWidth values on the onload event for the
    document. After you make your adjustments, set the visibility to visible.



    "Afshin" <> wrote in message
    news:...
    > Hi,
    >
    > I am trying to create a very long dynamic document with fixed width
    > for the cells of my table iin HTML, I need to truncate some of the
    > information that I display to fit in the table.
    >
    > As the document is very long I can not use the offsetwidth
    > functionality of the cell because then the user will see the
    > information being truncated, which is not desireable, I was wondering
    > if there is any way of calculating the width of the text displayed in
    > the "risky" rows on the fly before the whole document gets rendered.
    >
    > I tried to display the information in the row and then try to truncate
    > it right away after using the offsetwidth to see the width of the text
    > in pixel, but this is not working as the offsetwidth needs the whole
    > document to be rendered before being able to calculate the exact
    > value.
    >
    > If anybody has any idea of how to do this on the fly I would
    > appreciate yor help.
    >
    > Thanks
    >
    > Afshin
    Mike, Dec 10, 2003
    #2
    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. AndrewF
    Replies:
    1
    Views:
    773
    Bruce Barker
    Oct 10, 2005
  2. Xu
    Replies:
    11
    Views:
    8,554
    Andrew Thompson
    Jul 16, 2005
  3. Sean Jorden
    Replies:
    1
    Views:
    594
    laurie
    Aug 19, 2003
  4. kris
    Replies:
    11
    Views:
    873
  5. Paul Furman

    min-width max-width again

    Paul Furman, Feb 9, 2004, in forum: HTML
    Replies:
    10
    Views:
    706
    Beauregard T. Shagnasty
    Feb 9, 2004
Loading...

Share This Page