Sunday, May 23, 2010

How to Print a part of webpage using Javascript

<html>
<head>
<title>Print a part of HTML or Webpage using Javascript</title>
<script type="text/javascript">
function printDiv()
{
   var divToPrint=document.getEelementById('areaToPrint');
  newWin= window.open("");
  newWin.document.write(divToPrint.outerHTML);
  newWin.print();
  newWin.close();
}

</script>
</head>
<body>

<div id="areaToPrint">
The text you want to print or the content you want to print
</div>
</body>
</html>

---> The Javascript function can be called using an ANCHOR link or a onClickevent for a button or else in body onload function.

No comments: