Rob Champagne

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromRob Champagne
ToMe
Subjectevent listener for Firefox browser font size change
Date21 August 2006 14:15
Hello,

Well its a worth a try cos I've had no joy elsewhere...

Short version: 

Is a way there a way to trap a browser "font size" change in Firefox. i.e.
is an "event" fired in Firefox when the user uses the font size option?
Specifically I'm looking for an "onresize" event on a "DIV" but any "Event"
on any element would do.
Changing font size causes a resize of DIV's containing text and that is what
I'm trying to trap.
I have tried/looked at all recommended options and various forums with no
joy. I made it work in IE6 but Gecko DOM ref says there is no resize event
fired on a DIV and it doesn't appear to happen in firefox.

Thank you.

Rob Champagne
FromMe
ToRob Champagne
SubjectRe: event listener for Firefox browser font size change
Date21 August 2006 21:37
Rob,

> Mozilla DOM reference says there is no resize event on a DIV so is
> there a work around to make it work in FIREFOX?

The W3C make the DOM standard, not Mozilla. It is used by all current
standards based browsers, such as Opera, Safari, Konqueror, iCab, and the
Mozillas (such as Firefox). The relevant spec is DOM level 2 events, section
'HTML event types'.

Most specifically this part:

"resize
The resize event occurs when a document view is resized."

This means that it only applies when changing the size of the browser window
or frame, and applies to the document (meaning it will fire on the window
object in all these browsers). It cannot be used on individual elements.

What you are trying to do is possible, but not the way you think. Instead of
listening for an event, you must monitor the font size of an element, and
see when it changes. Use an interval to check if the computed fontSize style
of the body element has changed. If it has, they have changed the size of
the font.

This will work if the font size is changed in Safari, Konqueror, iCab, and
Mozilla. It will work in Opera if the minimum font size is changed. It will
not work in Opera if they zoom, but that usually takes care of everything
itself, so you will not need to change anything anyway.

> I read your advice and
> tried Opera but there does't seem to be an equivalent font resize
> option.

Tools - Preferences - Advanced - Minimum font size. Normally Opera uses zoom
(which zooms both the text, and everything else like images), and the
minimum font size just sets a hard limit on normal font sizes.


Sample script:
var lastSize;
if( window.getComputedStyle ) {
 lastSize = window.getComputedStyle(document.documentElement,null).fontSize;
 setInterval(function () {
  var sz = window.getComputedStyle(document.documentElement,null).fontSize;
  if( sz != lastSize ) {
    //do whatever fixes you wanted
    lastSize = sz;
   }
 },500);
} else {
 //do the IE hackaround
}


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromRob Champagne
ToMe
SubjectRe: event listener for Firefox browser font size change
Date21 August 2006 22:58
Mark,

Thanks for your help. It works a treat!

incidentally, I found your site to be the most understandable/readable on
the web for real explanations of how to use Javascript.

Thanks again.


Rob Champagne
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.