473,768 Members | 7,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I find a size of font in the current element?

I know about element.style.f ontSize, but it seems to work here (with Mozilla
Firefox 1.0.6) just only when the fontSize was set via CSS. Can I get
somewhere current size of the font in the actual element. Explanation:
PeopleSoft uses very small font (9pt), which on Mozilla looks pretty small.
Unfortunately, it is set somewhere in their Javascript, so apparently it
fools even "Minimal font size" in Mozilla's settings. Therefore, I would
love to make small greasemonkey script to go through all elements on the
page and increase size of the fonts when it is lower than some threshold
(11pt?). Currently, the only thing I could do (and it works surprisingly
well, considering brutality of my script) is this:

---------------------------------------------------------------

// FixPSFonts
// version 0.1
// 2005-10-21
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script that removes all CSS styles
// from selected sites.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Unstyle", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name FixPSFonts
// @namespace http://www.ceplovi.cz/matej/progs/scripts
// @description remove all font-size in CSS styles
// @include *
// ==/UserScript==

(function() {
var stylesheets, i, all, element;
all = document.getEle mentsByTagName( '*');
for (i = 0; i < all.length; i++) {
all[i].style.fontSize = "11pt";
}
})();

//
// ChangeLog
// 2005-10-21 - 0.1 - MC - first attempt (quite brutal one! :-))
//

---------------------------------------------------------------

Is there a way how to bit more gentle and change only some font sizes?

Thanks for any tip,

Matěj

--
Matej Cepl, http://www.ceplovi.cz/matej/blog/
GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC

Whenever Christ our life is revealed, then also you will be
revealed with Him in glory.
-- Colossians 3:4 (Green's Literal Translation)

Oct 21 '05 #1
3 2537
Matej Cepl wrote:
(function() {
var stylesheets, i, all, element;
all = document.getEle mentsByTagName( '*');
for (i = 0; i < all.length; i++) {
all[i].style.fontSize = "11pt";
`pt' is a unit suited for printing, not for desktop presentation.
How large (i.e. how many pixels) `11pt' actually is on the screen
depends on the font resolution. This in turn depends on the
display resolution which depends on the graphics driver which
depends on the operating system and platform. Which is too many
variables to be reliable, and it is known to have resulted in
illegible text on certain standard configurations.

Use the `em' unit or percentages instead. (Alas using the `px'
unit is known to prevent zooming fonts in all-too-buggy IE).
Is there a way how to bit more gentle and change only some font sizes?


Access and manipulate the style-sheet object and its rules itself.
Ask Google (Groups) for details, we had this several times before
(in the not-too-far past).
PointedEars
Oct 21 '05 #2
Matej Cepl wrote:
I know about element.style.f ontSize, but it seems to work here (with
Mozilla Firefox 1.0.6) just only when the fontSize was set via CSS. Can I
get somewhere current size of the font in the actual element. Explanation:
PeopleSoft uses very small font (9pt), which on Mozilla looks pretty
small. Unfortunately, it is set somewhere in their Javascript, so
apparently it fools even "Minimal font size" in Mozilla's settings.
Therefore, I would love to make small greasemonkey script to go through
all elements on the page and increase size of the fonts when it is lower
than some threshold (11pt?). Currently, the only thing I could do (and it
works surprisingly well, considering brutality of my script) is this:


OK, so I found in other thread about getComputedStyl e, but I was not able to
make some comparison on it. I've tried this, but I this does not seem to
work (no change happens):

function getComputedStyl eValue (element, property) {
return element.ownerDo cument.defaultV iew.getComputed Style(element, ''
[property];
}

(function() {
var i, all, element;
all = document.getEle mentsByTagName( '*');
for (i = 0; i < all.length; i++) {
element = all[i];
strVal = getComputedStyl eValue(element, "fontSize") ;
if (strVal == "12px") { // I would actually want val <= 12
element.style.f ontSize = "11pt";
}
}
})();

What I would like if command in the main function do is to compare actual
size of the element (however, it gets to be of such size) and if it is less
than 10pt (or 13px; I know it is not exact, but I do not care that much)
then set element.style.f ontSize to "11pt". How to translate to integer
value? Should I just split the strVal by RegEx and convert to Number()?

Best,

Matej

--
Matej Cepl, http://www.ceplovi.cz/matej/blog/
GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC

He has the attention span of a lightning bolt.
-- Robert Redford

Oct 21 '05 #3
> Should I just split the strVal by RegEx and convert to Number()?

Yep.

str = new String('112px') ;
result = str.match(/^(\d+)(\D+)$/);
val = Number(result[1]) + 6

and val ends up being 118 (and you could even grab the units from
result[2])

Though if you do the subtraction operation, instead of addition, with
result[1], I don't even think you need the explicit conversion.

Oct 21 '05 #4

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

Similar topics

27
3326
by: skeeterbug | last post by:
please see http://www.geocities.com/operationsengineer1/test.htm for an idea of how i want my logo header div to be layed out. when i went to resize "Test" to 2em (from 1em), this is what happened... http://www.geocities.com/operationsengineer1/test1.htm
9
3778
by: Dr John Stockton | last post by:
Assuming default set-ups and considering all reasonable browsers, whatever that may mean, what should an author expect that his readers in general will see (with visual browsers) for a page with body like <br><br> Abc <font size=+1> Abc <font size=+1> Abc <font size=+1> Abc <font size=+1> Abc <font size=+1>
16
2458
by: maya | last post by:
I have heard so much preaching here about how font sizes should be set as percentages so users can change font-sizes on their browsers... ok, so now at work am working on a site where we need to do precisely that b/c it's for an audience that some users maybe be visually-impaired.. but I can't get it to work right, problem is that font sizes are not consistent across diff elements.. code: body {text-align:center; /* to center...
40
2977
by: Paul Davis | last post by:
Hi all, I'm building some style sheets and trying to play the old game of balancing designer pixel perfection and still allowing users to adjust their font sizes. The compromise I've made with the designer is that he'll accept allowing users to change font sizes it it "looks right" with the default setting. I'm using em to set the font size. So, anyway, here's the problem. At 0.96em we get the perfect font size. But, if the font is...
24
5349
by: Harris Kosmidis | last post by:
I have a site up and running (www.solsoft.gr). I tested it with FF2 and IE6 and works ok with some IE hacks. Ok the CSS isn't good cause I started designing it with another look and the customer ended up wanting a 3-column layout. Now I see that IE7 mess things up. First of all there's a left margin which I don't know why it exists. Secondly when I see the page the fonts are way too big. I first had body{font-size:0.62em} but now...
30
4544
by: Takehiko Abe | last post by:
I have a <pelement with <ttinside: ;;; <p>A paragraph contains <tt>tt element</tt>.</p> I would like to set the font-size of the TT to the same as the containing <p>. This does not seem to work: ;;; p {
18
25004
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin, that IE7 does not seem to offer any way to control the font size of a text input element.
11
8893
by: Ram | last post by:
Hey, I've got the following code: <font font-size="7">Hello</font> How can I calculate the font-size int the actual size in pixels? Thanks ahead! --sternr
3
3300
by: coyttl | last post by:
Hey guys, I'm sure I'm doing something dumb but can't figure out exactly what it is... Here are details: XHTML Transitional pages with a linked CSS page. (See the CSS bits below) On Firefox 2.0.0.3, if I have a span with a style/class containing a "font-size" or "font-size-adjust" in it, it appears normally. In IE 7 (don't have any other IEs to test against at this moment), the font-size remains unchanged, no matter what I put into...
0
9413
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10025
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...
0
9848
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...
1
7391
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
6660
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5292
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...
0
5429
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3543
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.