spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column92


Print Templates, Part III: HeaderFooter

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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 < oSpanCollection.length; i++) {
    if (oSpanCollection[i].className ==
    "hfPageTotal") {
      oSpanCollection[i].innerText =
        myheaderfooter.pageTotal;
	}
  }
}

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


http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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

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