Possible Duplicate:
How can I measure how many characters will fit the width of the document?
I’m developing a mobile website and I’ve run into a problem. The site gets the mobile device’s screen size and needs to calculate how many characters it can fit on the screen. Once this information is known, a string of that length will be pulled from the server using AJAX.
The problem is, I am not sure how I can perform this calculation using JavaScript. Does anybody know how I can solve this problem?
Unless you use a fixed-width font, you can’t. Not without knowing the text’s contents in advance. That’s because in every normal font, every character (and sometimes, even every character pair) has a different width.
Maybe elaborate some more about your requirement. I’m fairly sure there is a much simpler solution for what you need to do.