如何使用JavaScript导入字体文件? [英] How to import font file using JavaScript?

查看:219
本文介绍了如何使用JavaScript导入字体文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CSS有 @ font-face 规则允许我们使用自定义字体。

CSS has a @font-face rule which allows us to "use" custom fonts.

JavaScript是否具有此功能?

Does JavaScript have this functionality?

更具体地说,是否可以在不使用CSS @ font-face 规则的情况下使用自定义字体?

More specifically, is it possible to "use" custom fonts without using the CSS @font-face rule?

推荐答案

除了使用 @ font-face 规则。您可以从理论上从JavaScript创建 @ font-face 规则,而无需使用 document.write (或 document.createElement(style) etc),如果您使用 CSS对象模型;但我现在不会指望在任何浏览器中实现。

There is no way to cause the browser to load a font from the network other than with a @font-face rule. You could theoretically create that @font-face rule from JavaScript without having to use document.write (or document.createElement("style") etc), if instead you used the CSS Object Model; but I wouldn't count on that to be implemented in any browser at the moment.

这篇关于如何使用JavaScript导入字体文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆