使用JavaScript获取系统字体

仅有两种方法可以使用JavaScript获取系统字体。 以下是带有演示的参考链接。

使用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; }

源 演示

另一种方式

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.'); }

错误:
未捕获的TypeError:对象[object Object]的属性'fontList'不是函数

演示版

From: https://www.sitepoint.com/system-fonts-javascript/

你可能感兴趣的:(前端,javascript,java)