spacer

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

home / experts / javascript / column92


Print Templates, Part III: HeaderFooter

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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