473,503 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with getting fontSize on body tag

Hi, I am writing a function to change the font-size but I am running
into a snag. I cannot get the current font-size of the body. Here is
a link to a simplified test case

http://mustang.millersville.edu/~wst...ng/mu/test.php

You would think that it would alert 72.5% when you click the resize
button, but it alerts nothing. If i add the style to the body tag
(style="font-size: 72.5%;" ), then it works.

Here is the test case code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;
charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<script type="text/javascript">

function resizeText()
{
alert(document.getElementsByTagName('body')[0].style.fontSize);
}

</script>
<style type="text/css">

body {
background: transparent url('../img/bg_pattern.gif') repeat 0 0;
font-size: 72.5%;
font-family: 'Trebuchet MS', Arial, Helvetica, sans-serif
}

</style>
</head>
<body>

<p>Test Test Test Test Test Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test Test Test Test</p>

<p>Text Resize&nbsp; <a href="#" id="grow"
onclick="resizeText()">A<sup>+</sup></a</p>

</body>
</html>

Thanks in advance!

Jun 8 '07 #1
6 7917

Adam Risser wrote:
Hi, I am writing a function to change the font-size but I am running
into a snag. I cannot get the current font-size of the body. Here is
a link to a simplified test case

http://mustang.millersville.edu/~wst...ng/mu/test.php
var body=document.body;
var fs=
(
body.currentStyle||
(window.getComputedStyle&&getComputedStyle(body,nu ll))||
body.style
).fontSize;
alert(fs);

Jun 8 '07 #2
On Jun 8, 3:45 pm, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
Adam Risser wrote:
Hi, I am writing a function to change the font-size but I am running
into a snag. I cannot get the current font-size of the body. Here is
a link to a simplified test case
http://mustang.millersville.edu/~wst...ng/mu/test.php

var body=document.body;
var fs=
(
body.currentStyle||
(window.getComputedStyle&&getComputedStyle(body,nu ll))||
body.style
).fontSize;
alert(fs);

Thank you for your help. When I put that in an onload function, it
returns the size in pixels.
I am looking hopefully to just return whatever font-size is set in the
css. (In this case, 72.5%)

I have no real idea how that snippet works, but it is interesting :P
Thanks again!

Jun 8 '07 #3
rf

"Adam Risser" <ar*****@gmail.comwrote in message
news:11*********************@q69g2000hsb.googlegro ups.com...
Hi, I am writing a function to change the font-size
Ctrl mouse wheel?

--
Richard.
Jun 9 '07 #4
On Jun 8, 11:02 pm, "rf" <r...@invalid.comwrote:
"Adam Risser" <aris...@gmail.comwrote in message

news:11*********************@q69g2000hsb.googlegro ups.com...
Hi, I am writing a function to change the font-size

Ctrl mouse wheel?

--
Richard.
I am looking to have A+ and A- buttons on the site so people can
change the font who do not know about Ctrl mouse wheel

Jun 13 '07 #5
On Jun 8, 3:55 pm, Adam Risser <aris...@gmail.comwrote:
On Jun 8, 3:45 pm, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
Adam Risser wrote:
Hi, I am writing a function to change the font-size but I am running
into a snag. I cannot get the current font-size of the body. Here is
a link to a simplified test case
>http://mustang.millersville.edu/~wst...ng/mu/test.php
var body=document.body;
var fs=
(
body.currentStyle||
(window.getComputedStyle&&getComputedStyle(body,nu ll))||
body.style
).fontSize;
alert(fs);

Thank you for your help. When I put that in an onload function, it
returns the size in pixels.
I am looking hopefully to just return whatever font-size is set in the
css. (In this case, 72.5%)

I have no real idea how that snippet works, but it is interesting :P
Thanks again!
No dice unless you use an inline style attribute on the body tag (not
a good idea.) Regardless, this is a waste of time; leave the font
sizing to the user agent.

Jun 20 '07 #6
On Jun 13, 10:27 pm, Adam Risser <aris...@gmail.comwrote:
On Jun 8, 11:02 pm, "rf" <r...@invalid.comwrote:
"Adam Risser" <aris...@gmail.comwrote in message
news:11*********************@q69g2000hsb.googlegro ups.com...
Hi, I am writing a function to change the font-size
Ctrl mouse wheel?
--
Richard.

I am looking to have A+ and A- buttons on the site so people can
change the font who do not know about Ctrl mouse wheel
Most will tell not to try, users can change the font size themselves a
number of ways. On a 33cm screen at 1280x800px I have the default
font set to 18pt, on a 48cm screen at 1280x1024px I have it set to
14pt. I can use ctrl+"plus" to make it bigger at any time I like, ctrl
+"minus" to make it smaller.

But since you wont heed that advice, use CSS and modify a style rule
that sets the body's font size in percentage. Some browsers will
report the font size in whatever units were used to set it, others
will report in whatever unit they wish, regardles of what was used to
set it. You will need to test thoroughly.
--
Rob

Jun 20 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2290
by: Dariusz | last post by:
I am trying out a fully CSS-P layout (first time with floats) and am having problems with getting certain DIV's from displaying properly - or rather - they are being completely ignored. Below is...
2
3854
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
7
3570
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
1
1507
by: tshad | last post by:
I am running a program to put a captcha image on my string and am trying to make sure all the characters fit. The problem is the size seems to be wrong. What I am doing is starting from the...
4
22047
by: jnag | last post by:
Hello, Through an onClick() event, I have an inline function to change the font size of the page (actually, I need to do this for the entire website). I have this defined in the header.cfm file...
2
2435
by: davidson1 | last post by:
Hai friends..for menu to use in my website..i found in one website....pl look below website.... http://www.dynamicdrive.com/dynamicindex1/omnislide/index.htm i downloaded 2 files.... ...
3
2328
by: Rajneesh Chellapilla | last post by:
Hi I made this marquee program however, I am having trouble getting all four marquees to line up correctly. Basically I want the the 4 marquees to line up on the four sides exactly so they intersect....
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.