Borodin Borodin - 7 days ago 6
Javascript Question

How can I tell whether a 'font-family' request was honoured so that I can substitute an image if necessary?

I have a CSS file that uses

@font-face
to refer to a font resource on a networked server. Can I write client-side JavaScript that puts an image in place of styled text if a CSS
font-family
request fails because the server is unavailable?

Answer

I'm partial to this font detection helper: http://www.lalit.org/lab/javascript-css-font-detect/

After including the .js file, here is the example usage:

// Usage
var detective = new Detector();
alert(detective.test('font name'));