Thursday, August 6, 2009

Print Friendly Version

There will be scenarios where you want to print a page without the Print Icon or Close buttons. All you need to do is put the printable data inside a dive and then add the iframe tag at the end of that screen and on print load the ifram with the div content. Here is the code.


function ClickToPrint() {
try {
var oIframe = document.getElementById('ifrmPrint');
var oContent = document.getElementById('divprint').innerHTML;
var oDoc = (oIframe.contentWindow oIframe.contentDocument);
if (oDoc.document) oDoc = oDoc.document;
oDoc.write("<><>title< /title>");
oDoc.write("< /head>< onload="'this.focus();">");
oDoc.write(oContent + "< /body>");
oDoc.close();
return false;
}
catch (e) {
self.print();
}
}

No comments:

Post a Comment