Skip to content

Instantly share code, notes, and snippets.

@say2joe
Created November 2, 2012 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save say2joe/4004695 to your computer and use it in GitHub Desktop.
Save say2joe/4004695 to your computer and use it in GitHub Desktop.
JS Printer (for DOM Node)
{
css: "path/to/cssForPrinting.css",
print: function(DOMobj){
var winPrinter = window.open('', "SLPPrinter", "width=900,height=525,top=150,left=150,toolbars=no,scrollbars=yes,status=no,resizable=yes"),
html = (DOMobj.jquery)? DOMobj.parent().html() : (DOMobj.parentNode)? DOMobj.parentNode.innerHTML : (DOMobj.innerHTML || '');
if (document.createStyleSheet) document.createStyleSheet(this.css); else // Dynamically added CSS is different for IE.
$("head",winPrinter.document).append($("<link/>").attr({ rel: "stylesheet", type: "text/css", href: this.css }));
$("body",winPrinter.document).append(html); winPrinter.focus(); winPrinter.print(); winPrinter.close();
return DOMobj;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment