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 while Rendering

The deficiency of template4 is its low performance. We first assemble all pages and then we insert the header's and footer's HTML. We re-layout the pages while inserting the headers and footers, and this is relatively an expensive operation. We present a more efficient way to populate the headers and footers in template5.html. The difficulty in preparing the header while laying out the page content, is that we need to know the total number of pages for the "Page x of y" message. The trick is to layout the header and footer during the page content assembling, and then update the total number of pages field at the end. In this way, we don't re-layout the page. We just update a field in an existing page, which is less expensive. You can actually observe this algorithm during its execution. In template4.html you saw the headers and footers appearing at the end, after all pages have already been laid out. In template5.html, you can see that the header and footer are laid out together with the page content, except for the total number of pages that is being added at the end.

Download template5.html to your drive from Column92.zip or copy and paste it from Page 8. Once it is on your hard drive, enter its full path name in the Template Source field. Click the Print Preview button to see the effect of the template.

The skeleton of template5 is similar to template4's. The function addFirstPage() assembles the first page. The event handler onPageComplete() fires off whenever a page completes. If there is an overflow, we call addNewPage(). Otherwise, we call addPageTotalToPages() to update the total number of pages on all pages. Notice that we call addHeaderAndFooterToPage() when we assemble the whole page, either in addFirstPage() or in addNewPage().

Next: How to Update Headers and Footers

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