JavaScript
Article

Getting System Fonts Using JavaScript

By Sam Deering

Just a couple of ways to get the System Fonts using JavaScript. There are ref links below with demos.

Getting System Fonts Using JavaScript

try {
    //adds a swf to the page and reads fonts
    $('body').append('
'); $('#flashcontent').flash( { "src": "resources/FontList.swf", "width": "1", "height": "1", "swliveconnect": "true", "id": "flashfontshelper", "name": "flashfontshelper" }, { update: false }); //timeout required for swf to settle. setTimeout(function() { console.log(window.fonts); return window.fonts; }, _this.settings.flashDelay); } catch(ex) { _this.errors.push('No fonts detected.'); return fonts; }

Source Demo

Another way

try {
    //adds a swf to the page and reads fonts
    $('body').append('
').flash( { "src": "resources/fonts.swf", "width": "1", "height": "1", "swliveconnect": "true", "id": "flashfontshelper", "name": "flashfontshelper" }, { update: false }); //timeout required for swf to settle. setTimeout(function() { var fonts = "", obj = document.getElementById("flashfontshelper"); //get fonts if (obj && typeof(obj.GetVariable) != "undefined") { fonts = obj.GetVariable("/:user_fonts").replace(/,/g,", "); } if (!fonts) { fonts = "No Flash or Java fonts detected"; _this.errors.push('No Flash or Java fonts detected.'); } console.log(fonts); return fonts; }, 100); return true; } catch(ex) { fonts = this.errors.push('No Flash or Java fonts detected.'); }

errors:
Uncaught TypeError: Property ‘fontList’ of object [object Object] is not a function

Demo

No Reader comments

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.