spacer

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

home / experts / javascript / column92


Print Templates, Part III: HeaderFooter

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Adding Headers and Footers after Rendering

The following lines from onPageComplete() actually add headers and footers to all pages:

myheaderfooter.textHead = printer.header;
myheaderfooter.textFoot = printer.footer;
myheaderfooter.url =
  dialogArguments.__IE_BrowseDocument.URL;
myheaderfooter.title =
  dialogArguments.__IE_BrowseDocument.title;
myheaderfooter.pageTotal =
  document.all.tags("DEVICERECT").length;

for (i = 1; i
  <= myheaderfooter.pageTotal; i++) {
  myheaderfooter.page = i;
  addHeaderAndFooterToPage(i);
}

headersFootersAdded = true;

The HeaderFooter element has an ID of myheaderfooter. The first line of code above sets the textHead property of myheaderfooter. This property includes textual instructions for generating the HTML code of the header. We take these instructions from the TemplatePrinter element (ID=printer):

myheaderfooter.textHead = printer.header;

The TemplatePrinter element stores user's directives regarding the header and footer. Use the Print Setup dialog box to modify the header and footer. We set the footer in a similar way:

myheaderfooter.textFoot = printer.footer;

We set the next two properties, url and title, from the document that is currently displayed. We get a reference to the document object through dialogArguments.__IE_BrowseDocument. URL and title are properties of this object:

myheaderfooter.url =
  dialogArguments.__IE_BrowseDocument.URL;
myheaderfooter.title =
  dialogArguments.__IE_BrowseDocument.title;

We compute the total number of pages by counting the number of DEVICERECT elements:

myheaderfooter.pageTotal =
  document.all.tags("DEVICERECT").length;

We then iterate over all pages. We set HeaderFooter's page property to the current loop index, and call addHeaderAndFooterToPage():

for (i = 1; i <= myheaderfooter.pageTotal; i++) {
  myheaderfooter.page = i;
  addHeaderAndFooterToPage(i);
}

Next: How to assemble the header and footer

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


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/3.html