By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,129 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Width of a String

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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?
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #2

P: n/a

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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

P: n/a
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
************************************
Jul 20 '05 #4

P: n/a


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5

P: n/a
Afshin P wrote:
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
Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.