Skip to content

Instantly share code, notes, and snippets.

@n0m4dz
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n0m4dz/c506ecbff318ce60eea9 to your computer and use it in GitHub Desktop.
Save n0m4dz/c506ecbff318ce60eea9 to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="text/javascript">
window.PrintView = function(elem)
{
var content = document.getElementById(elem).innerHTML;
var mywindow = window.open('', 'my div', 'height=600,width=900');
mywindow.document.write('<html><head><title>my div</title>');
mywindow.document.write('</head><body >');
mywindow.document.write(content);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10
mywindow.print();
mywindow.close();
return true;
};
</script>
</head>
<body>
<div id="printDiv">
Print this one.
</div>
<div>
not print it
</div>
<input type="button" value="Print Div" onclick="PrintView('printDiv')" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment