JS font tester

Download: testfont.js

API

var testfont = function(
    font /* Name of the font to test. */
)

Example

Mac OS X has a particularly beautiful monospace font called Monaco, but it only looks good in 10px, and all default monospace fonts should be 12px in size. To deal with this, we load Monaco from JavaScript:
var text = document.getElementById("MyElement");

if (testfont("Monaco") && (window.opera
          || navigator.vendor.indexOf("Apple") >= 0)) {
      text.style.fontFamily = "Monaco";
      text.style.fontSize = "10px"
}
Note that we also test for the browser here. This is because browsers such as firefox do not use the native Mac OS X text rendering API, and they make Monaco look ugly.