How to iterate the installed fonts using javascript?
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>
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/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With