Inventory of available computer fonts

Hey there, I've got a div containing text that changes based on the font selected from a dropdown list I created. Currently, my font options are limited because I have to manually add them one by one.

Is there a way to dynamically populate the font list with all the installed fonts on the user's computer using code, rather than manually adding each one?

HTML

<div id="generate">
       Change the text! 
</div>

<select id="box" onchange="font();">
    <option id="PIC" value="Choose a font">Choose a font.</option>
    <option id="TNR" value="TimesNewRoman">Times New Roman</option>
    <option id="GRG" value="Georgia">Georgia</option>
    <option id="PLT" value="PalatinoLinotype">Palatino Linotype</option>
    <option id="ARL" value="Arial">Arial</option>
    <option id="CMS" value="ComicSans">Comic Sans</option>
    <option id="IMP" value="Impact">Impact</option>
    <option id="TMS" value="TrebuchetMS">Trebuchet MS</option>
    <option id="TSB" value="TheSansBlack">The Sans Black Plain</option>
</select><br />

Javascript

 function font() {
        var sf = document.getElementById('box').value;
        var generate = document.getElementById('generate');

        switch(sf){
            case 'TimesNewRoman': 
                generate.style.fontFamily = ('Times New Roman')
                break;
            case 'Georgia': 
                generate.style.fontFamily = ('Georgia')
                break;
            case 'PalatinoLinotype': 
                generate.style.fontFamily = ('Palatino Linotype')
                break;
            case 'Arial': 
                generate.style.fontFamily = ('Arial')
                break;
            case 'ComicSans': 
                generate.style.fontFamily = ('Comic Sans MS')
                break;
            case 'Impact': 
                generate.style.fontFamily = ('Impact')
                break;
            case 'TrebuchetMS': 
                generate.style.fontFamily = ('Trebuchet MS')
                break;
            default: generate.style.fontFamily = ('')
            }
        }

Answer №1

If you're looking to see if a specific font is available, check out this helpful resource:

One approach is to generate your own list of fonts and cross-reference it with the information provided in the link above. This way, you can display only the fonts that are actually present on the user's system.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transforming XML into XSLT: An Innovative Approach

I am facing a challenge with an XML File that contains a very large amount of content. Fortunately, I have an xsd file to accompany this xml document. For example: Take a look at this link If you want to view the XML Content: To access the XSD for that ...

The React Component has been displayed on the screen a total of 5 times within the Ionic

While working on my app that includes a dashboard to display data, I noticed in Chrome's console that the render method is being called 5 times. This results in an annoying bouncing effect when the app page is re-rendered. How can I prevent the render ...

Integrate yaml-loader into the i18n settings of a Vue-CLI 3 project

After diving into the Vue-i18n library and exploring this tutorial, I successfully incorporated tags in json format within my project created with vue-cli. While browsing through the documentation, I noticed an example using yaml instead of json. However ...

Modifying body appearance using CSS

Can someone help me figure out why the background color isn't changing on my website? I'm not a fan of CSS so please go easy on me. App.css body { background-color: darkslategray; } App.js import { Box, ChakraProvider, Image } from "@c ...

Utilize JavaScript to retrieve data from a JSON document

To extract information from a .json file in node.js, the require function is used. I'm currently developing an Artificial Neural Network that utilizes this code to fetch data from the data.json file. const fs = require('fs'); const json = ...

Drawing a personalized cursor using JavaScript on a canvas

I've been working on creating a canvas that allows for drawing in vanilla JavaScript. Although I've successfully enabled drawing on the canvas, I'm now looking to implement a feature where a preview dot shows up when the user presses down be ...

Having trouble launching the emulator in VS Code for React Native?

I'm having trouble launching the android emulator on VS Code to run React-Native. I already have an emulator set up in Android Studio, but when I try to launch it, I get the error message: Error Failed to launch emulator. Reason: No emulators found as ...

A guide on displaying an Angular Component within a Thymeleaf page

Currently, I am faced with the task of integrating Angular and Thymeleaf. This is necessary because I have developed a dynamic graph using Angular and now need to incorporate it into an existing project that utilizes Thymeleaf. Are there any simplified m ...

Are there any design techniques for websites that can help make CSS more stable and less unpredictable?

What inspires me to write this question is my passion for creating visually appealing websites, although I struggle with CSS. I believe that the key is trial and error. It's all about experimenting, testing in different browsers, and refining the des ...

What are some effective methods for retrieving data through an ajax request?

Incorporating ajax into my javascript code has presented a challenge. $('#btnCart').click(function() { var pName = document.getElementById('prodName').value; $.ajax({ url: 'index.php', data: 'prd ...

Show data from html input using PHP

Here is the HTML and PHP code I have been working on. I am trying to display the inputted data, but I am not getting any output. Can you help me identify what is wrong with my code? HTML <form action="welcome.php" method="POST"> <fieldse ...

Tips for setting up jQuery on Mantis Bug Tracker

Several add-ons available on the Mantis website require the installation of the jQuery plugin before they can be used. After attempting to install a Mantis plugin, an error message in the control panel indicates that there is a missing dependency: jQuery ...

Content not being loaded by ajax

I am facing an issue with a button that is supposed to increase the quantity of a product. Here is the code snippet: <input name="quantity-"'.$item_id.'" " id="quantity-'.$item_id.' " type="text" value="' . $quantity . '" ...

Error Assertion found at /accounts/tcresults

I encountered an issue with the following details: AssertionError at /accounts/tcresults No exception message supplied. The error seems to be stemming from my code in tc.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

PHP script designed to monitor the expiration of a license and send a notification to the administrator approximately one month in advance

Looking for php code to keep track of expiration dates for registered workers' licenses. The admin should also receive notifications when a worker's license is about to expire or has already expired, so they can send an email to the worker. Here ...

Two arrays with varying sizes, utilizing one array repeatedly within a loop once its maximum index is reached

I have two arrays set up, and my goal is to iterate through the larger array and assign a property to it using randomly selected IDs from the smaller array. //The actual length of the users array is 140 const users = [ { name: "John Roberts", ui ...

Using AngularJS to pass objects dynamically through ng-include

Below is an example that is fully functional, except for one issue. When using node.title within the HTML code, everything works as expected. However, when trying to use {{node.title}} within the ng-include file, it does not function properly. Only the g ...

Got a value of `false` for an attribute `closable` that is not meant to be a

Here's the code snippet I have: import { Modal } from "antd"; import styled from "styled-components"; export const StANTModal = styled(Modal)` & .ant-modal-content { border-radius: 20px; overflow: hidden; } `; And ...

Error: Unable to access property 's_path' as it is not defined (React Native)

How can I resolve this problem? I'm relatively new to React Native and have been attempting to address this issue for the past 48 hours. TypeError: Cannot read property 's_path' of undefined This error is occurring in: in List (at Sear ...

Building intricate structures in Typescript: A comprehensive guide

My objective is to create a sophisticated object, with values that need to be calculated or extracted from another object. The specific object I am working on is defined as follows: interface A extends B { key1: string key2: { it's a complex object ...