HTML/JavaScriptBuild a Print Page Template
Listing 2. A standard template holds the printable content of a Web page. It utilizes JavaScript to provide the printing functionality. ![]() <script language=javascript src="Printing.js"> </script> <body onload="JavaScript:PopulateGenericPrintingWindow();"> <table width="100%" bgcolor="silver" ID="Table1"> <tr> <td>SAMPLE HEADER</td> </tr> </table> <br> <div id="Content">Placeholder</div> <br> <table width="100%" bgcolor="silver" ID="Table2"> <tr> <td>SAMPLE FOOTER</td> </tr> </table> </body> </html> function PopulateGenericPrintingWindow() { var PrintFrame; // This routine expects the caller to have a DIV named PrintContent // and the desination template to have a DIV named Content // which can then be surrounded by all of the formatting you want // The original page also needs a hidden IFRAME called // HiddenPrintFrame to receive the focus and print this.document.all['Content'].innerHTML = parent.document.all['PrintContent'].innerHTML; PrintFrame = parent.frames['HiddenPrintFrame']; if (PrintFrame) { // IE requires you to set focus first PrintFrame.focus(); PrintFrame.print(); } } |