473,804 Members | 3,697 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.dt d">
<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. getElementsByTa gName('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="resize Text()">A<sup>+ </sup></a</p>

</body>
</html>

Thanks in advance!

Jun 8 '07 #1
6 7932

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.b ody;
var fs=
(
body.currentSty le||
(window.getComp utedStyle&&getC omputedStyle(bo dy,null))||
body.style
).fontSize;
alert(fs);

Jun 8 '07 #2
On Jun 8, 3:45 pm, "scripts.contac t" <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.b ody;
var fs=
(
body.currentSty le||
(window.getComp utedStyle&&getC omputedStyle(bo dy,null))||
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******** *************@q 69g2000hsb.goog legroups.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.c omwrote:
"Adam Risser" <aris...@gmail. comwrote in message

news:11******** *************@q 69g2000hsb.goog legroups.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.contac t" <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.b ody;
var fs=
(
body.currentSty le||
(window.getComp utedStyle&&getC omputedStyle(bo dy,null))||
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.c omwrote:
"Adam Risser" <aris...@gmail. comwrote in message
news:11******** *************@q 69g2000hsb.goog legroups.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
2306
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 a copy of the code I have written. It is arranged as follows: Header Left Middle Right Footer The "Left" and "Right" DIV's are fixed width and the "Middle" DIV takes the
2
3904
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 http://home.pacific.net.sg/~jacksony ? (the drop down bar could not work at www.apchosting.net but can drop at home.pacific.net.sg. I suspect it is a server problem but was told it is not possible, therefore assuming it is a client script problem? the script works last time...
7
3624
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> </head> <style type="text/css">
1
1533
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 rectangles' height + 1 (not sure why I would use that as a starting point) then I loop through subtracting the value by 1 until the size I get back from MeasureString is less than the rectangle width.
4
22083
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 as: onclick="document.body.style.fontSize='50%';" This does not work at all for some reason. Whereas,
2
2470
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.... menuitems.js mmenu.js
3
2342
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. Three of them look good. With fourth the marquee does something funny this is illustrated if you change the border color of the "up" marquee in the program. Help and insights would be appreciated. Here is the program, it is computationally...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10577
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10320
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9150
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5521
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.