Print Templates, Part III: HeaderFooter: Adding Headers and Footers after Rendering - Doc JavaScript
Print Templates, Part III: HeaderFooter
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
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/3.html