Related to this blog: http://blog.kaelig.fr/post/33373448491/testing-font-face-support-on-mobile-and-tablet
Created
October 11, 2012 16:42
-
-
Save kaelig/3873753 to your computer and use it in GitHub Desktop.
Font-face detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isFontFaceSupported = (function () { | |
if (!!navigator.userAgent.match(/(Android (2.0|2.1))|(Nokia)|(OSRE\/)|(Opera (Mini|Mobi))|(w(eb)?OSBrowser)|(UCWEB)|(Windows Phone)|(XBLWP)|(ZuneWP)/)) { | |
return false; | |
} | |
var sheet, | |
doc = document, | |
head = doc.head || doc.getElementsByTagName('head')[0] || docElement, | |
style = doc.createElement("style"), | |
impl = doc.implementation || { hasFeature: function () { return false; } }; | |
style.type = 'text/css'; | |
head.insertBefore(style, head.firstChild); | |
sheet = style.sheet || style.styleSheet; | |
var supportAtRule = impl.hasFeature('CSS2', '') ? | |
function (rule) { | |
if (!(sheet && rule)) { return false; } | |
var result = false; | |
try { | |
sheet.insertRule(rule, 0); | |
result = !(/unknown/i).test(sheet.cssRules[0].cssText); | |
sheet.deleteRule(sheet.cssRules.length - 1); | |
} catch (e) { } | |
return result; | |
} : | |
function (rule) { | |
if (!(sheet && rule)) { return false; } | |
sheet.cssText = rule; | |
return sheet.cssText.length !== 0 && !(/unknown/i).test(sheet.cssText) && | |
sheet.cssText | |
.replace(/\r+|\n+/g, '') | |
.indexOf(rule.split(' ')[0]) === 0; | |
}; | |
return supportAtRule('@font-face{font-family:"font";src:"font.ttf";}'); | |
})(); | |
if (isFontFaceSupported) { | |
document.getElementsByTagName('html')[0].className += ' ff'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx for that! :) 👍