Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Width of a String

Reply
Thread Tools

Width of a String

 
 
Afshin
Guest
Posts: n/a
 
      12-06-2003
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
 
Reply With Quote
 
 
 
 
Fabian
Guest
Posts: n/a
 
      12-06-2003
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

 
Reply With Quote
 
 
 
 
Afshin P
Guest
Posts: n/a
 
      12-06-2003

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!
 
Reply With Quote
 
L. 'Perfect' Gordon
Guest
Posts: n/a
 
      12-06-2003
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
************************************


 
Reply With Quote
 
Afshin P
Guest
Posts: n/a
 
      12-09-2003


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!
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      12-10-2003
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox width scaling to width of data not width of page? AndrewF ASP .Net 1 10-10-2005 04:38 PM
JComboBox width, dropdown list width Xu Java 11 07-15-2005 11:54 PM
min-width max-width again Paul Furman HTML 10 02-09-2004 06:20 PM
Table width and columns width kris HTML 11 11-18-2003 06:49 AM
Re: resized image in table extends table width to original image width Sean Jorden HTML 1 08-19-2003 08:59 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57