Guys this is a nice piece of code which has been tested in IE7 to print the contents of a div. I got this code from http://www.webdeveloper.com/forum/showthread.php?t=152798

While printing keep in mind that on the printed copy you will lose all css styles.
<script type=”text/javascript”><!–
function ClickHereToPrint(){
try{
var oIframe = document.getElementById(‘ifrmPrint’);
var oContent = document.getElementById(‘divToPrint’).innerHTML;
var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
if (oDoc.document) oDoc = oDoc.document;
oDoc.write(“<head><title>title</title>”);
oDoc.write(“</head><body onload=’this.focus(); this.print();’>”);
oDoc.write(oContent + “</body>”);
oDoc.close();
}
catch(e){
self.print();
}
}
// –></script>

<body>

<a onclick=”ClickHereToPrint();”>Print</a>

<iframe id=’ifrmPrint’ src=’#’ style=”width:0px; height:0px;”></iframe>
<div id=”divToPrint”>
content
</div>
</body>

I Wan to share this post:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • kick.ie
  • Live
  • MyShare
  • IndianPad
  • Reddit
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • DotNetKicks
  • DZone
  • TwitThis