Skip to content

Instantly share code, notes, and snippets.

@AllThingsSmitty
Created April 24, 2016 13:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AllThingsSmitty/716e8b64f04fbf4d21c3c63e54d4a487 to your computer and use it in GitHub Desktop.
Save AllThingsSmitty/716e8b64f04fbf4d21c3c63e54d4a487 to your computer and use it in GitHub Desktop.
Dynamically check if Font Awesome CDN loaded
function css(element, property) {
return window.getComputedStyle(element, null).getPropertyValue(property);
}
window.onload = function () {
var span = document.createElement('span');
span.className = 'fa';
span.style.display = 'none';
document.body.insertBefore(span, document.body.firstChild);
if ((css(span, 'font-family')) !== 'FontAwesome') {
// add a local fallback
}
document.body.removeChild(span);
};
@dhaupin
Copy link

dhaupin commented Aug 15, 2017

Cool idea, thanks.

BTW, foNTweSOMe can be called with any case. So you should take the font-family and toLowerCase() then compare against the lowercase fontawesome.

@shramee
Copy link

shramee commented Mar 15, 2018

I guess default should be fine... 😜 Thanks Matt, really nice! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment