列出用户浏览器可以显示的每种字体 [英] list every font a user's browser can display

查看:357
本文介绍了列出用户浏览器可以显示的每种字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在javascript中获取浏览器可以显示的所有字体(或字体族)的名称? (我想给用户一个下拉列表所有可用的字体的列表,并允许用户选择一种字体。)
我不想提前硬编码这个列表或发送它下来服务器。 (直观地,浏览器应该知道它有什么字体,这应该暴露给javascript某种方式。)

Is there a way in javascript to obtain the names of all fonts (or font-families) that the browser can show? (I want to give the user a dropdown with a list of all available fonts, and allow the user to choose a font.) I'd prefer not to have to hardcode this list ahead of time or send it down from the server. (Intuitively, it seems like the browser should know what fonts it has and this should be exposed to javascript somehow.)

推荐答案

JavaScript版本有点薄。它通过迭代已知的字体和测试获得字体。

The JavaScript version is a bit flaky. It gets fonts by iterating through known fonts and testing.

最准确的方法(尽管必须使用适当的插件)是使用Flash 。在这里你可以得到字体列表,而不必使用尺寸单独测试它们。

The most accurate way (albeit having to use a propriety plugin) is to use Flash. Here you can get the list of fonts without having to test for them individually using dimensions.

你将不得不决定是否有一个确切的列表,在某些设备(iDevices,不含Flash插件的浏览器等)上工作,或者通过仅通过JavaScript提供更好支持的部分列表

You are going have to decide whether to have an exact list at the expense of not working on some devices ( iDevices, browsers without Flash plugin, etc), or a partial list with better support via JavaScript only.

这篇关于列出用户浏览器可以显示的每种字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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