Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate the installed fonts using javascript? [duplicate]

Tags:

javascript

How to iterate the installed fonts using javascript?

like image 247
xport Avatar asked Aug 30 '10 03:08

xport


2 Answers

This code works for IE

<html>
<head>
    <script type="text/javascript">
    <!--
        function getFonts() {

            // get list of fonts, and sort alphabetically
            var allFonts = [];
            for (var loop = 1; loop < dlgHelper.fonts.count + 1; loop++) allFonts[loop - 1] = dlgHelper.fonts(loop);
            allFonts.sort();

            // create output list, and include samples of each font
            var outputStr = '';
            var fontTestString = 'ABC abc 123';
            for (var loop = 0; loop < allFonts.length; loop++) {
                outputStr += '<span style="font-family: ' + allFonts[loop] + ';">' + allFonts[loop] + '</span><br />\n';
            }
            document.getElementById('fontList').innerHTML = outputStr;
        }
     //-->
    </script>
</head>
<body onload="getFonts();">
    <object id="dlgHelper" classid="clsid:3050F819-98B5-11CF-BB82-00AA00BDCE0B" width="0px"
        height="0px">
    </object>
    <div id="fontList">
    </div>
</body>
</html>
like image 137
Kundan Atre Avatar answered Nov 08 '22 17:11

Kundan Atre


Javascript's sandboxed inside the browser and doesn't have privileges to read from the clients disk for security reasons.

However people tried making some workarounds like http://www.lalit.org/lab/javascript-css-font-detect or http://remysharp.com/2008/07/08/how-to-detect-if-a-font-is-installed-only-using-javascript/.

like image 38
Kris van der Mast Avatar answered Nov 08 '22 18:11

Kris van der Mast