Width of a String

A

Afshin

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
 
F

Fabian

Afshin hu kiteb:
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.

The default behaviour is you force width for a table cell is that the
text would then flow to create a new row of text within that cell. What
have you done which would prevent this, and why?
 
A

Afshin P

Hi Fabian,

thanks for the response. I forgot to mention that I want to prevent the
wrapping of the information that is why I am trying to truncate the
text.

Thanks again

Afshin
 
L

L. 'Perfect' Gordon

A quick way to get this done is to create a hidden div tag and upon
page load, innerHTML the string into the div, get it's width, do your
truncations, and then load the altered text from the div into the cell.
Although the page is rendered, the user doesn't see the truncation.

I hope this answers the question you've placed.

--
************************************
MUSIC24SEVEN
Pioneers of the
'Digital Entertainment Industry'
http://music24seven.com
************************************
 
A

Afshin P

Hi and thanks for your response.

How can you find the width of the InnerHTML of a Div BEFORE that the
page is loaded completly?

Thanks
 
T

Thomas 'PointedEars' Lahn

Afshin said:
How can you find the width of the InnerHTML of a Div BEFORE that
the page is loaded completly?

You cannot. Display depends on various variables, including font
family, font size, font style, font scale and viewport size.

If you depend on any of those variables, your design is flawed if
not even borken.


PointedEars
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top