const font = new FontFace("molot", 'url("/shared-assets/fonts/molot.woff2")', {
style: "normal",
weight: "400",
stretch: "condensed",
});
document.fonts.add(font);FontFaceSet: check() method / notebook
FontFaceSet: check() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
console.log(document.fonts.check("12px molot"));
// false: the matching font is in the set, but is not yet loadedconsole.log(document.fonts.check("12px Courier"));
// true: the matching font is a system fontconsole.log(document.fonts.check("12px i-dont-exist"));
// true: the matching font is a nonexistent fontconsole.log(document.fonts.check("12px molot, Courier"));
// false: `molot` is in the set but not yet loadedfunction check() {
font.load();
console.log(document.fonts.check("12px molot"));
// false: font is still loading
console.log(font.status);
// "loading"
}
check();async function check() {
await font.load();
console.log(document.fonts.check("12px molot"));
// true: font has finished loading
console.log(font.status);
// "loaded"
}
check();