Compartir a través de


HEADERFOOTER Element | HeaderFooter Behavior

Provides a tool so that a print template can convert header and footer formatting strings to formatted HTML.

Syntax

XML
  	&lt;HEADERFOOTER<code> ID=</code>sID /&gt;
  	</td>
HTML N/A
Scripting N/A

Possible Values

sID String that specifies a unique identifier for the object.

Members Table

The following table lists the members exposed by the HeaderFooter object.

Attribute Property Description
DATELONG dateLong

Sets or retrieves the current date in long format.

DATESHORT dateShort

Sets or retrieves the current date in short format.

font

This method gets or sets the font properties for the header and footer.

htmlFoot

Retrieves the HTML representation of the footer, as specified by the footer formatting string entered in the textFoot property of the HeaderFooter behavior.

htmlHead

Retrieves the HTML representation of the header, as specified by the header formatting string entered in the textHead property of the HeaderFooter behavior.

PAGE page

Sets or retrieves the page number that the HeaderFooter behavior uses when generating HTML for headers and footers.

PAGETOTAL pageTotal

Sets or retrieves the page total that the HeaderFooter behavior uses when generating HTML for headers and footers.

TEXTFOOT textFoot

Sets or retrieves the control string used by the HeaderFooter behavior to generate HTML for the footer.

TEXTHEAD textHead

Sets or retrieves the control string used by the HeaderFooter behavior to generate HTML for the header.

TIMELONG timeLong

Sets or retrieves the current time in long format.

TIMESHORT timeShort

Sets or retrieves the current time in short format.

TITLE title

Sets or retrieves the title of the document currently being printed or print-previewed.

URL url

Sets or retrieves the URL of the document currently being printed or print-previewed.

Remarks

The HeaderFooter behavior is a conversion tool used by a print template to generate HTML from the header and footer formatting strings in the Page Setup dialog box.

A HEADERFOOTER element is intended for use when building a print template. Its functionality is disabled when it is used outside a print template.

To use this behavior, enter a header formatting string and footer formatting string into the textHead and textFoot properties of a HeaderFooter element located on a print template. These strings can be obtained by inserting a TemplatePrinter element in a print template and retrieving the header and footer properties from it. The formatting strings can also be custom-created without regard to the values displayed in the Page Setup dialog box. Depending on the specifications of the formatting strings, you also need to set several properties as follows:

  • Enter the page URL into the url property of the HeaderFooter behavior. You can obtain the URL from the document object referenced by the __IE_BrowseDocument property of the dialogArguments object or the contentDocument property of the LAYOUTRECT element.
  • Enter the document title into the title property of the HeaderFooter behavior. You can obtain the title from the document object referenced by the __IE_BrowseDocument property of the dialogArguments object or the contentDocument property of the LAYOUTRECT element.
  • Enter the page number into the page property of the HeaderFooter behavior. The print template calculates the page number for each page.
  • Enter the page total into the pageTotal property of the HeaderFooter. The print template calculates the page total for the print job.
  • The HeaderFooter behavior calculates an initial value for the dateShort, dateLong, timeShort and timeLong properties automatically when the HeaderFooter behavior is first instantiated. These values can be changed.

From these properties, the HeaderFooter behavior creates formatted HTML for a header and footer based on the specifications of the formatting strings. You can retrieve this HTML from the htmlHead and htmlFoot properties of the HeaderFooter behavior and place it in the pages ( DeviceRect) of your print template.

To format a custom header or footer, use the following codes to specify the information to be printed. The codes can be combined with text (for example, " Page &p of &P").

Desired Text Code
Window title &w
Page address (URL) &u
Date in short format (as specified by Regional Settings in Control Panel) &d
Date in long format (as specified by Regional Settings in Control Panel) &D
Time in the format specified by Regional Settings in Control Panel &t
Time in 24-hour format &T
Current page number &p
Total number of pages &P
Centered text (following &b) &b
Right-aligned text (following &b&b) &b&b
A single ampersand (&) &&

The conversion offered by the HeaderFooter behavior is one-way. That is, the HeaderFooter behavior converts formatting strings to HTML; it doesn't convert HTML to formatting strings.

This element should occur only once in a printer template.

When using the HEADERFOOTER element, you must prefix it with an XML namespace. Declare the namespace using the IMPORT processing instruction. For example, the namespace "IE" can be declared by the following statement:

<?import implementation="#default" namespace="IE">

The HEADERFOOTER element syntax to use with this namespace is <IE:HEADERFOOTER ... />.

The HEADERFOOTER element is an unscoped element; that is, it does not have a closing tag. It must have a forward slash (/) before its closing bracket.

security note Security Alert  Writing an Microsoft ActiveX control, binary behavior, or other binary object for use on a Web page that can load an unspecified print template can compromise the security of your application. Such a control could be appropriated to load insecure or malicious print templates. Write your control to load only specific, pre-defined templates. For more information, please review Safety Considerations When Using Print Templates and Designing Secure ActiveX Controls.

Examples

Click below to download a sample application that demonstrates the print and print preview features of Windows Internet Explorer. The application includes eight templates that increase in complexity from minimal functionality to those that include user interface elements. You can also use the application to test templates of your own design. You must download the sample application to your own computer to run it.

Download Print and Preview Template Test Application

The following example shows how you might use the HeaderFooter behavior to add headers and footers to the pages of a print job once all the LAYOUTRECT and DEVICERECT elements have been created to render a template's source document. For clarity, only the header and footer styles are shown. Notice the Boolean variable headersFootersAdded. Even though the headers and footers are absolutely positioned and shouldn't change the other elements in a DeviceRect, the current implementation of the LayoutRect behavior re-flows the content in the LAYOUTRECT elements when the DEVICERECT elements in a print template change. During the re-initialization, the onlayoutcomplete event fires again for the LAYOUTRECT elements, leading to an infinite loop of calls to the onlayoutcomplete handler function, which is OnRectComplete in this example. The variable headersFootersAdded switches to true after the first pass through the pages to prevent the repagination from adding headers and footers a second time.

Another strategy to deal with this problem is to add headers and footers during the initial creation of LAYOUTRECT elements. The page total would then be added after the layout is complete. For an example of this strategy, see Tmplt5.htm in the sample application.

<HTML XMLNS:IE>
<HEAD>
<?import namespace="ie" implementation="#default">
<STYLE type="text/css">
.header
{
    position:absolute;
    top:.25in;
    width:6in;
    left:1in;
}
.footer
{
    position:absolute;
    top:10.5in;
    width:6in;
    left:1in;
}
</STYLE>
<SCRIPT language="JScript">
var headersFootersAdded = false;

function OnRectComplete()
{
    if (event.contentOverflow == true)
        AddNewPage();
    else if (headersFootersAdded == false)
    {
        headfoot.textHead = printer.header;
        headfoot.textFoot = printer.footer;
        headfoot.url = dialogArguments.__IE_BrowseDocument.URL;
        headfoot.title = dialogArguments.__IE_BrowseDocument.title;
        headfoot.pageTotal = document.all.tags("DEVICERECT").length;
        for (i = 1; i <= headfoot.pageTotal; i++)
        {
            headfoot.page = i;
            AddHeaderAndFooterToPage(i);
        }
        
        headersFootersAdded = true;
}

function AddHeaderAndFooterToPage(pageNum)
{
    newHeader = headfoot.htmlHead;
    newFooter = headfoot.htmlFoot;
    
    document.all("page" + pageNum).insertAdjacentHTML("afterBegin", newHeader); 
    document.all("page" + pageNum).insertAdjacentHTML("beforeEnd", newFooter);
}

function AddNewPage()
{
    // This function adds a LAYOUTRECT and possibly a DEVICERECT,
    // depending on the requirements of this particular print template
}
</SCRIPT>
</HEAD>

<BODY>

<IE:TEMPLATEPRINTER id="printer"/>
<IE:HEADERFOOTER id="headfoot"/>

<DIV id="pagecontainer">
    <IE:DEVICERECT id="page1" media="print" class="pagestyle">
        <IE:LAYOUTRECT id="LRect1" contentsrc="document" 
                       onlayoutcomplete="OnRectComplete()" 
                       nextRect="LRect2" class="layoutstyle"/>
    .
    .
    .

See Also

LayoutRect, DeviceRect, TemplatePrinter, dialogArguments, IDM_PRINT, IDM_PRINTPREVIEW, Beyond Print Preview: Print Customization for Internet Explorer 5.5, Print Preview 2: The Continuing Adventures of Internet Explorer 5.5 Print Customization