Skip to content

Instantly share code, notes, and snippets.

@alirobe
Created November 4, 2011 03:31
Show Gist options
  • Save alirobe/1338595 to your computer and use it in GitHub Desktop.
Save alirobe/1338595 to your computer and use it in GitHub Desktop.
SharePoint 2010 Font Loader
// in IE only, we must ensure that we don't load the font when the page is loaded in a dialog, because this
// breaks the font reference.
// Dialogs work by appending ?isDlg=1 to the end of an existing page and loading it into an iFrame.
function loadFont(fontName) {
var iAmInternetExplorer = navigator.userAgent.indexOf('MSIE') != -1;
var iAmNotInADialog = window.location.href.indexOf('IsDlg') == -1;
// for other browsers, we load this in a conditional comment.
// due to a bug in IE, WOFF fonts can't be loaded twice.
if (iAmInternetExplorer && iAmNotInADialog) {
var css_tag = document.createElement('link');
var head = document.getElementsByTagName('head')[0];
css_tag.setAttribute('rel','stylesheet');
css_tag.setAttribute('type','text/css');
css_tag.setAttribute('href','/Style Library/fonts/'+fontName+'/stylesheet.css');
head.appendChild(css_tag);
// We inserted before DOM was loaded! This is probably OK, but verify after the DOM is loaded
if(typeof jQuery!== "undefined") {
jQuery(function() {
// for some reason the tag wasn't added to the head, so add...
if(head.innerHTML.indexOf(fontName) == -1) {
head.appendChild(css_tag);
}
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment