How can I calculate the font-size int the actual size in pixels?
Thanks ahead!
--sternr
that code is insanely bad. you can't do it.
you should be setting font sizes, and everything else related to display,
via CSS instead of in tags themselves.
Hey,
I know this is bad, but it's not my code - long story short - I cant
change this html...
isn't there a way of doing that?
Thanks again
--sternr
you could probably get the "font-size" of the font, but you would not be
able to get the size in pixels.
I think here is a typo. The font element has no attribute "font-size".
Correct is "size":
<font size="7">Hello</font>
>>How can I calculate the font-size int the actual size in pixels?
>>Thanks ahead!
>>--sternr
You can try next approach.
Create in runtime a font element, set it font size to known value in
pixels and compare this element with the font element which size you
want to define. Increase the size in series and at some point of time
you will get required value.
Short example:
<html>
<script type="text/javascript">
function checkSize()
{
var fonts = document.getElementsByTagName("font");
var checkedElem = fonts[0];
var height = checkedElem.offsetHeight;
for(var i = 0; i < 100; i++)
{
var tempFont = document.createElement("font");
tempFont.style.fontSize = i + "px";
tempFont.innerHTML = checkedElem.innerHTML;
document.body.appendChild(tempFont);
var tempHeight = tempFont.offsetHeight;
document.body.removeChild(tempFont);
if (tempHeight >= height)
{
alert("Font size = " + i + "px");
break;
}
}
}
</script>
<body onload="checkSize()">
<font size="7">Hello</font>
</body>
</html>
I do? Don't answer that, you probably wouldn't quote it and end up
confusing anybody trying to follow the conversation. Besides, monitor
resolution is trivial.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
You have already shown your inability to read and comprehend what you
read so I won't expect you to understand what I am about to explain to
you. I only post it in the hopes that someone else reads it and doesn't
fall into your position.
Just because *you* can't do it doesn't mean it can't be done, it means
you can't do it. Yet you said you would have to know something that is
trivial to determine and in the end it is irrelevant.
So you are also a self admitting liar? Nice.