This script is a JavaScript module that detects when the font size has changed. You can create a function to notify you every time the font is changed.
This is a self contained module, no external libraries are required to run it though it will run nicely beside one if you like!
Please see the release page.
Put this in your HTML somewhere (head will be fine, make sure it's loaded first):
<script src="fsdetect.min.js" type="text/javascript"></script>
Then code something like this in your own JavaScript file to detect font size changes:
FontSizeDetector.changed( function(e)
{
//This code is run every time the font size has been changed
//Uncomment the below to see font size changes:
//console.log(e);
});
If you've got a JavaScript file that detects and resizes accorinding to the screen size, you may also want to look at this. When a user changes their font size, be it through an older browser, a mobile browser or a plugin you may find that your script is breaking. I came across this when developing a carousel, everything worked fine until font size was changed!
Nope, there's an onresize event for the Window however this does not get triggered when someone changes their font size. There may be plans to add this to future browsers.
Sure, if you want to unbind an event that you've stored as a variable (eg. myFunction) just call this:
FontSizeDetector.unbind( myFunction );
Or if you just want to unbind everything:
FontSizeDetector.unbind();