Home » » Print a div with javascript

Print a div with javascript

Written By Unknown on Senin, 20 Juni 2011 | 02.49

Hello Friends. Sometimes yoy want to print contents of only a div and not the whole window. Use this little javascript function.

Just click on the print button and the contents of the div will be printed.

The Javascript

 <script type="text/javascript">    
function PrintThis() {
var printThisDiv=document.getElementById('print-cntnt');
var popup=window.open('','_blank','width=400,height=350');
popup.document.open();
popup.document.write('<html><body onload="window.print()">'
+ printThisDiv.innerHTML + '</html>');
popup.document.close();
}
</script>


The Html

  <div id="print-cntnt">
Contents of the div to be to printed !!
</div>
<input type="button" value="Print" onClick="PrintThis();">


Demo

Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger