calculate how many fix-width characters can fit horizontally and vertically in a window

Hello,

I would like to calculate how many fix-width characters can fit horizontally and vertically in a window.

Here is my css:
                pre {
                font-family: fixed, monospace;
                font-size: 16px;
                letter-spacing: 4px;
                line-height: 18px;
                }

Exactly how many characters can I fit across and down in a user's window?

LVL 16
hankknightAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LordWolfyCommented:
First you need to determine the window width and height, then simply divide by the font width and height (which you would declare as constants in your javascript)


var font_width = 16;   // put your own values here
var font_height = 16;   
 
window_width = document.body.offsetWidth; // this works in IE
window_height = document.body.offsetHeight; // not sure about FF
 
chars_across = window_width / font_width;
chars_down = window_heighth / font_height;

Open in new window

0
LordWolfyCommented:

oops - typo in the last line - should read:
chars_down = window_height / font_height;

Open in new window

0
LordWolfyCommented:
actually - i naffed up the whole thing - I wish they have edit / delete options in this thing.

Here is the PROPER version :p


var font_width = 16;   // put your own values here
var font_height = 16;   
 
var window_width = document.body.offsetWidth; // this works in IE
var window_height = document.body.offsetHeight; // not sure about FF
 
var chars_across = window_width / font_width;
var chars_down = window_heighth / font_height;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LordWolfyCommented:
and i pasted it with teh broken last line again - I'm sure you can figure it out ;)

Thats it - I'm going to bed!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.