spacer

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

home / experts / javascript / column92


Print Templates, Part III: HeaderFooter

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

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.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags


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