Print Templates, Part III: HeaderFooter: Updating Headers and Footers - Doc JavaScript | WebReference

Print Templates, Part III: HeaderFooter: Updating Headers and Footers - Doc JavaScript


Print Templates, Part III: HeaderFooter

Updating Headers and Footers

In template5, we need to assemble the HeaderFooter element at the beginning. We do it in addFirstPage():

  myheaderfooter.textHead = printer.header;
  myheaderfooter.textFoot = printer.footer;
  myheaderfooter.url =
    dialogArguments.__IE_BrowseDocument.URL;
  myheaderfooter.title =
    dialogArguments.__IE_BrowseDocument.title;

As in template4, we first fill HeaderFooter's textHead and textFoot properties. We just copy them from TemplatePrinter's header and footer properties. These properties reflect the user's entries in the Print Setup dialog box. We also populate the url and title properties from the document currently displayed. We take these properties from the document object that is passed through dialogArguments.__IE_BrowseDocument.

The other change from template4 is the addition of addPageTotalToPages(). In this function we update the total number of pages in all headers' "Page x of y" message. Here is the function:

function addPageTotalToPages() {
  oSpanCollection = document.all.tags("span");
  for (i = 0; i 

This function is based on some implementation details of the HeaderFooter behavior. More precisely, on how it assembles the field of total number of pages in the header's HTML. The field is laid out within a SPAN element, and its className property is "hfPageTotal". The className property is one of the properties of the SPAN object. The function above simply searches for all SPAN elements of the page, finds the one with className property equal to "hfPageTotal", and updates its innnerText property with the total number of pages (myheaderfooter.pageTotal).

Next: Template4's code listing


https://www.internet.com


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: September 10, 2001
Revised: September 10, 2001

URL: https://www.webreference.com/js/column92/6.html