3

Is there a way to let the user choose a font from their own computer with Javascript?

Sorry if this sounds a bit basic, but I googled for it and all I found was hundreds of thousands of tutorials on how to use style.fontFamily. That, however, is not what my problem is. I already know how to set a font.

I want to allow the user to set a certain piece of text to a certain font they can choose themselves. Like in this fiddle.

<p>
   Type a font name: <input id="font" /> and click
   <button type="button" id="button">here</button>
</p>
<p id="example">
   And this is the text that will be displayed in the chosen font.
</p>
document.getElementById('button').onclick = function() {
 document.getElementById('example').style.fontFamily =
  document.getElementById('font').value;
};

Except I want the input to have a datalist that contains the font names on the user's computer. Or it can be a select.

Some libraries look promising at first sight, such as "JQuery Font Chooser", but that too uses a preset list instead of using the actually available fonts.

By now it almost looks as if fetching font names from the client computer is not possible...

Mr Lister
  • 44,061
  • 15
  • 107
  • 146
  • Possible duplicate of http://stackoverflow.com/questions/3368837/list-every-font-a-users-browser-can-display – Declan Cook Mar 22 '14 at 13:00
  • would they have to upload their own font file, like a .ttf? – Johnny Rockex Mar 22 '14 at 13:04
  • @DeclanCook Oh, I see. Yes, this is a duplicate, and apparently I used the wrong search terms. – Mr Lister Mar 22 '14 at 13:11
  • @JohnnyRockex No, I just mean the installed fonts. You know, like you get in your browsers preferences window, where you choose which font you want to use for serif, sans-serif etc. – Mr Lister Mar 22 '14 at 13:13

0 Answers0