Saturday, May 4, 2013

Print using javascript

<html>
<body>
<input type="button" value="click" onclick="printDiv()">
<div id="divToPrint">hello</div>
</body>
</html>
<script>
function printDiv()
{
 
  var divToPrint=document.getElementById('divToPrint');
  var newWin=window.open('','Print-Window','width=100,height=100');
//alert(divToPrint.innerHtml);
  newWin.document.open();
  newWin.document.write('<html><body>'+divToPrint.innerHTML+'</body></html>');
window.print()
  //newWin.document.close();
  //setTimeout(function(){newWin.close();},10);
}
</script>

No comments:

Post a Comment