Forum Moderators: open

Message Too Old, No Replies

FontSelect()?

How does one determine the available fonts?

         

jmf314159

12:18 pm on Mar 9, 2005 (gmt 0)

10+ Year Member



How can I interrogate the system to determine the fonts available?

Bernard Marx

3:02 pm on Mar 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't (from a browser).
You can test each font individually and see if the browser is just using the default font, by a width comparison. A real dodgy hack...

<html><head>
<title>Test</title>
<style type="text/css">
.fonttest
{
width: auto;
padding: 0;
height: auto;
position: absolute;
left: 0; top: 0px;
line-height: 1.2em;
visibility: hidden;
}
</style>
<script type="text/javascript">

function doTest()
{
alert(testFont(document.getElementById('fontbox').value))
}

function testFont(font)
{
var control = document.getElementById('control');
var test = document.getElementById('test');
test.style.fontFamily = font;
return control.offsetWidth!= test.offsetWidth;
}
</script>
</head>
<body>
<div id="control" class="fonttest">How wide is this text?</div>
<div id="test" class="fonttest">How wide is this text?</div>

<input type="button" onclick="doTest()" value="Enter font">
<input type="text" id="fontbox">
</body>
</html>

SpaceFrog

4:13 pm on Mar 9, 2005 (gmt 0)

10+ Year Member



just go for the most commonly spread fonts...

Times New Roman, Arial, Courier, Helvetica, verdana courrier new, tahoma ...

search on google for most common fonts ...

rocknbil

7:26 pm on Mar 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can't this be done using VBScript/ActiveX or a Java Applet?