HTML/JavaScript•Build 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">
<body onload="JavaScript:PopulateGenericPrintingWindow();">
   <table width="100%" bgcolor="silver" ID="Table1">
            <td>SAMPLE HEADER</td>
      <div id="Content">Placeholder</div>
      <table width="100%" bgcolor="silver" 
            <td>SAMPLE FOOTER</td>
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