共用方式為


LayoutRect

Creates a container element for document content in a print or print preview template.

Remarks

LAYOUTRECT elements define the area or areas (and their styles) on a page where a document's content is displayed when printed or during print preview. In a print template, LAYOUTRECT elements are contained by DEVICERECT elements, which define the printable area of the print template. A DEVICERECT can contain more than one LAYOUTRECT.

A LAYOUTRECT element is intended for use when building a print template. While this element renders on a Web page, most of its functionality is disabled when it is used outside a print template.

A print template typically has a series of connected LAYOUTRECTs into which a source document can flow as it is rendered for printing or previewing. The first LAYOUTRECT in the series defines the source of the content by specifying a contentSrc property or attribute. ContentSrc can be set to the string "document" to indicate that the current document displayed should be used as the source, or it can be set to a URL specifying another source. The LAYOUTRECT element also has a nextRect attribute or property to specify another LAYOUTRECT into which the source content should continue to flow once the current LAYOUTRECT is full. Each LAYOUTRECT in the series, except the last, defines a nextRect pointing to the next LAYOUTRECT in the series.

A print template usually handles documents of various lengths. It must provide enough LAYOUTRECT elements to accommodate an arbitrary amount of content. To accomplish this, use script to create LAYOUTRECTs dynamically, as a source document loads, by specifying an onlayoutcomplete event handler for each LAYOUTRECT. The event handler should check the event's contentOverflow property. When the contentOverflow property is true, the handler can create a new LAYOUTRECT with an id, an onlayoutcomplete handler, and a nextRect attribute pointing to the next LAYOUTRECT element in the series. The onlayoutcomplete event can fire more than once on a single LAYOUTRECT. For this reason, the event handler must cancel itself once it has been called, to prevent the handler from firing more than once.

A LAYOUTRECT element must have a style that defines a width and height; the default value for each of these properties is zero. A print template can obtain the current page setup information by querying the TemplatePrinter behavior properties, including marginBottom, marginLeft, marginRight, marginTop, pageWidth and pageHeight. A LAYOUTRECT style cannot redefine styles within the content source; for instance, it cannot redefine font-family or font-weight.

When using the LAYOUTRECT 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 using the following statement:

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

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

The LAYOUTRECT 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 Warning:  **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 Beyond Print Preview: Print Customization for Internet Explorer 5.5 and Designing Secure ActiveX Controls.

Examples

Click below to download a sample application that demonstrates the print and print preview features of 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 some of the basic elements of a print preview template, including the onlayoutcomplete event handler. Note that the LAYOUTRECT elements in this example define their nextRect attributes before the next LAYOUTRECT is added to the series. This template supports print preview, but not printing. For information on printing support, see the TEMPLATEPRINTER reference page.

<HTML XMLNS:IE>
<HEAD>
<?import namespace="ie" implementation="#default">
<STYLE type="text/css">
.layoutstyle
{
    margin:1in;
    width:4in;
    height:4in;
}
.pagestyle
{ 
    border:1 solid black;
    width:8.5in;
    height:11in;
    margin:5px;
}
</STYLE>
<SCRIPT language="JScript">
index = 1;

function OnRectComplete()
{
    if (event.contentOverflow == true)
    {
        document.all("LRect" + index).onlayoutcomplete = null;

        newHTML = "<IE:DEVICERECT id=page" + (index + 1) + "
        media=print class=pagestyle>";
        newHTML += "<IE:LAYOUTRECT id=LRect" + (index + 1) + "
        onlayoutcomplete='OnRectComplete()' nextRect=LRect" + (index
        + 2) + " class='layoutstyle'/>";
        newHTML += "</IE:DEVICERECT>";

        pagecontainer.insertAdjacentHTML("beforeEnd", newHTML);
        index++;
    }
}
</SCRIPT>
<HEAD>
<BODY>
<DIV id="pagecontainer">
<IE:DEVICERECT id="page1" media="print" class="pagestyle">
    <IE:LAYOUTRECT id="LRect1" contentsrc="document"
    onlayoutcomplete="OnRectComplete()" nextRect="LRect2"
    class="layoutstyle"/>
</IE:DEVICERECT>
</DIV>
</BODY>
</HTML>

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows 2000 Server

See also

Reference

DeviceRect

TemplatePrinter

HeaderFooter

dialogArguments

IDM_PRINT

IDM_PRINTPREVIEW

onlayoutcomplete

Other Resources

Beyond Print Preview: Print Customization for Internet Explorer 5.5

Print Preview 2: The Continuing Adventures of Internet Explorer 5.5 Print Customization