Skip to content

Instantly share code, notes, and snippets.

@joonassandell
Last active September 13, 2016 14:38
Show Gist options
  • Save joonassandell/52458fb9afb16c1ca966 to your computer and use it in GitHub Desktop.
Save joonassandell/52458fb9afb16c1ca966 to your computer and use it in GitHub Desktop.
Detecting font-face support
var ua = navigator.userAgent,
doc = document,
docEl = doc.documentElement;
/**
* Detect mobile "font-face" support
*
* Doesn't check support on desktop browsers
* so you should use Modernizr in combination with this
* UA detection to get the most out of it.
*/
var isMobileFontfaceSupported = (function () {
if (ua.match(/(Android (1.0|1.1|1.5|1.6|2.0|2.1))|(Nokia)|(Opera Mini)|(w(eb)?OSBrowser)|(webOS)|(UCWEB)|(Windows Phone OS 7)|(XBLWP7)|(ZuneWP7)/)) {
return false;
}
return true;
})();
if (!isMobileFontfaceSupported) {
docEl.className += ' no-fontface ';
// If used together with modernizr font-face detection:
// docEl.className = docEl.className.replace(/(^|\s)fontface(\s|$)/, ' no-fontface ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment