我想检测一下是否支持本地表情符号。
只有如果它不是,我会加载表情字体,以节省带宽,也使应用程序看起来更本机。
然而,当我在互联网上搜索时,我只发现有人在使用userAgent检查是否支持表情符号。
例如,下面的代码来自https://github.com/github/g-emoji-element/blob/master/emoji-detection.js,
export function isEmojiSupported(): boolean {
const onWindows7 = /\bWindows NT 6.1\b/.test(navigator.userAgent)
const onWindows8 = /\bWindows NT 6.2\b/.test(navigator.userAgent)
const onWindows81 = /\bWindows NT 6.3\b/.test(navigator.userAgent)
const onFreeBSD = /\bFreeBSD\b/.test(navigator.userAgent)
const onLinux = /\bLinux\b/.test(navigator.userAgent)
return !(onWindows7 || onWindows8 || onWindows81 || onLinux || onFreeBSD)
}尽管正则表达式可能并不完美,因为Windows7中的Firefox确实支持http://caniemoji.com/中的Emoji。
然而,由于不同浏览器或库可能具有不同的表情符号集,所以一些表情符号可能在一个浏览器中呈现得很好,而另一些只是呈现得不是很好。
那么,有没有比使用userAgent更好的方法来检查是否支持Emoji呢?
发布于 2019-10-21 10:57:34
与其尝试检测,我建议用你想要的所有字形加载字体,并在你的CSS中使用font-display: swap。
然后,您的页面仍然可以显示,同时加载这种额外的字体仍在发生。
https://stackoverflow.com/questions/58479029
复制相似问题