[Javascript] is their a javascript function, or DOM property to find the char limit of a table cell or div?

tedd tedd at sperling.com
Wed Jan 31 09:50:53 CST 2007


At 4:24 PM +0000 1/30/07, Lee Bettridge wrote:
>  was wondering if their is a way to find out how many characters 
>will fit into an area of a given size ?


Lee:

I had the same problem. The width and height of the viewing area (the 
frame) is not a problem, you can get that from the window attributes. 
The problem is number of characters and linefeeds that are contained 
in the body of the text and how much of that you can display in the 
frame allotted.

I started by reading in the text and building the amount I could 
display in the frame by counting characters and upon reaching the 
maximum width would then increment a line count. When I reached a 
linefeed, I would simply increment the line count and move on. When 
the maximum number of lines was reached, I was done.

I took my example a bit further by ending text at paragraphs and thus 
slightly less than what was allotted. I don't like dangling paragraph 
remnants.

The code I have is in php and very specific to my example so 
providing it would cause you more headache than working it out 
yourself, but I've given you the basics. It's not that much of a 
problem to figure out.

hth's

tedd

-- 
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com



More information about the Javascript mailing list