Is there a way to detect whether a user's browser is supporting @font-face?

天涯浪子 提交于 2019-12-19 10:27:33

问题


I have some content on a web page that uses funny fonts to display correctly by using @font-face to use some custom fonts. I include a warning that it might not display correctly on all browsers. The content isn't really essential to the page, so what I'd really like to do instead is simply not show it if the browser isn't going to do it, due to browser version, script blocking, or whatever. Is there a way to do that?


回答1:


Modernizr has this built-in. Here's a link to a build that just checks for @font-face support. http://modernizr.com/download/#-fontface-shiv-cssclasses-teststyles-load

Then you can check in JS for Modernizr.fontface or in the css for .fontface { }.

Here's a fancy explanation of how to do it: http://paulirish.com/2009/font-face-feature-detection/

To be clear you can pretty much support every browser with @font-face, except for some versions of Android. http://caniuse.com/#search=font

Your bigger problem with @font-face isn't the basic support for @font-face, but support for the specific font file type, which is more limited. I personally suggest to use WOFF, which works in IE9+. Alternatively, if you use Typekit or Font-Squirrel you can pretty much support all browsers out of the box.



来源:https://stackoverflow.com/questions/10339268/is-there-a-way-to-detect-whether-a-users-browser-is-supporting-font-face

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!