Created
February 2, 2009 23:05
-
-
Save kyleslattery/57160 to your computer and use it in GitHub Desktop.
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
/* | |
jQuery Font Detection Plugin by Kyle Slattery (http://kyleslattery.com) | |
Used to determine if a font is installed on a user's computer | |
Inspired by: http://remysharp.com/2008/07/08/how-to-detect-if-a-font-is-installed-only-using-javascript/ | |
Use: | |
if($.fontInstalled('Helvetica')) { | |
// font is installed | |
} else { | |
// font is not installed | |
} | |
*/ | |
$.fontInstalled = function(font) { | |
var test_string = 'mmmmmmmmmwwwwwww'; | |
var test_font = '"Courier New", monospace'; | |
var testbed = $('<div></div>').css({position: 'absolute', left: '-9999px', visibility: 'hidden'}); | |
var control = $('<span></span>').text(test_string).css({fontSize: '50px', fontFamily: test_font}).appendTo(testbed); | |
var tester = $('<span></span>').text(test_string).css({fontSize: '50px', fontFamily: font + ', ' + test_font}).appendTo(testbed); | |
testbed.appendTo('body'); | |
var installed = (control.width() != tester.width()) | |
testbed.remove(); | |
return installed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment