Skip to content

Instantly share code, notes, and snippets.

@stedman
Created February 12, 2010 17:09
Show Gist options
  • Save stedman/302758 to your computer and use it in GitHub Desktop.
Save stedman/302758 to your computer and use it in GitHub Desktop.
Load the print stylesheet after DOM loads (to avoid flash of unstyled content—FOUC).
// ref: http://stevesouders.com/tests/dhtml-stylesheet-settimeout.php
// load print stylesheet after DOM loads
function loadStylesheet() {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.media = 'print';
link.href = '/css/print.css';
document.getElementsByTagName('head')[0].appendChild(link);
}
// use1: jQuery(window).load(function(){loadStylesheet();})
// use2: setTimeout(loadStylesheet, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment