views:

88

answers:

2

Is there a way in javascript to obtain the names of all fonts (or font-families) that the browser can show? (I want to give the user a dropdown with a list of all available fonts, and allow the user to choose a font.) I'd prefer not to have to hardcode this list ahead of time or send it down from the server. (Intuitively, it seems like the browser should know what fonts it has and this should be exposed to javascript somehow.)

+8  A: 

Yes there is! I'm so glad you asked this question because I now want to use this too.

+1 for question, and here's your answer :)

http://www.lalit.org/lab/javascript-css-font-detect

Marko
Very devious. This is awesome.
recursive
+1. I just saw this the other day, too...definitely very cool. :D
Faisal
Thank you, yes this is useful once I have a list of fonts to test what is installed, but the problem is how to generate a list of font names in the first place.
Matt S
+3  A: 

The JavaScript version seems a bit flaky. It gets fonts by iterating through known fonts and testing.

The best way (albeit having to use a propriety plugin) is to use Flash. Here you can get the list of fonts without having to test for them individually using dimensions.

You are going have to decide whether to have an exact list at the expense of not working on some devices ( iDevices, browsers without Flash plugin, etc), or a partial list with better support.

alex