Remove header and footer from window.print()

, ,

Here is the code

Html

<div id="printableArea">
 <h1>Print me</h1>
</div> 
<input type="button" onclick="printDiv('printableArea')" value="print a div!" />

javascript

<script> 
function printDiv(elem)
{
    var mywindow = window.open('', 'PRINT', '');

    mywindow.document.write('<html><head><title>' + document.title  + '</title>');
    mywindow.document.write('</head><body >');
    mywindow.document.write('<h1>' + document.title  + '</h1>');
    mywindow.document.write(document.getElementById(elem).innerHTML);
    mywindow.document.write('</body></html>');

    mywindow.document.close(); 
    mywindow.focus();  

    mywindow.print();
    mywindow.close();

    return true;
} 
</script>






Related Post


Latest Post


Recent Posts Widget

Make sure to never miss a thing...

Get the latest news from the creative industry along with other creative goodies, conveniently delivered to social media.