August 13, 2001 - Turning Off Events
August 13, 2001 Turning Off Events Tips: August 2001
Yehuda Shiran, Ph.D.
|
onPageComplete()
that is used to create a dynamic print template:
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++;
}
}
Try it. Works perfectly. Now, let's omit the first line inside the if statement. We'll get the new onPageComplete()
function:
function onPageComplete() {
if (event.contentOverflow) {
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++;
}
}
Try it. You should get one blank page at the end. The reason for this is an extra event of onlayoutcomplete
of the previous page that we have already printed. The first line of onPageComplete()
sets it to null
before printing the next page:
document.all("layoutrect" + lastPage).onlayoutcomplete = null;
For more information on print templates, go to Column 89, Print Templates, Part I.