5

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...

André
  • 1,602
  • 2
  • 12
  • 26
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
  • 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
  • 1
    Does this answer your question? [list every font a user's browser can display](https://stackoverflow.com/questions/3368837/list-every-font-a-users-browser-can-display) – André Mar 20 '23 at 22:04
  • @André Yes, but the same link was already posted 9 years ago by Declan Cook, above. – Mr Lister Mar 30 '23 at 13:03
  • And after 9 years this still hasn't been marked as a duplicate. – André Mar 30 '23 at 13:57

0 Answers0