August 11, 2001 - Detecting A Page Overflow | WebReference

August 11, 2001 - Detecting A Page Overflow

Yehuda Shiran August 11, 2001
Detecting A Page Overflow
Tips: August 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

The event LayoutComplete fires when the DeviceRect element is done rendering. There are two possible reasons for the page to stop rendering. Either the source document is exhausted or the source overflows the page size. You can distinguish between them by the event property contentOverflow. Test event.contentOverflow. If it is true, then the source overflows the page. Otherwise, the source is exhausted.

The function onPageComplete() is called whenever the last page is overflowed by a longer source. We first check that indeed event.contentOverflow is true (Try it):

function onPageComplete() {
  if (event.contentOverflow) {
    document.all("layoutrect" + lastPage).onlayoutcomplete = null;
    newHTML  = "<IE:DEVICERECT ID='devicerect" + (lastPage + 1) +  
               "' MEDIA='print' CLASS='masterstyle'>";
    newHTML += "<IE:LAYOUTRECT ID='layoutrect" + (lastPage + 1) + 
               "' ONLAYOUTCOMPLETE='onPageComplete()' NEXTRECT='layoutrect" + 
               (lastPage + 2) + "'  CLASS='contentstyle'/>";
    newHTML += "</IE:DEVICERECT>";
    devicecontainer.insertAdjacentHTML("beforeEnd", newHTML);
    lastPage++;
  }
}
For more information on print templates, go to Column 89, Print Templates, Part I.