Skip to content

Instantly share code, notes, and snippets.

@kmlprtsng
Created August 22, 2013 11:00
Show Gist options
  • Select an option

  • Save kmlprtsng/6305834 to your computer and use it in GitHub Desktop.

Select an option

Save kmlprtsng/6305834 to your computer and use it in GitHub Desktop.
Print contents of a div tag
//<a href="javascript:void(0)" onclick="PrintElem('.panel-div')" class="btn">Print Div</a>
function PrintElem(elem)
{
PrintPopup($(elem).html());
}
function PrintPopup(data)
{
//Windows title in window.open itches the IE the wrong way.
var mywindow = window.open('', '', 'height=600,width=600');
mywindow.document.write('<html><head><title>Page Title</title>');
/*optional stylesheet*/mywindow.document.write('<link rel="stylesheet" href="style.css" type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.focus();
mywindow.print();
mywindow.close();
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment