Entry
How can I print document selective area only.
How to apply beforeprint, afterprint event for selective document area printout.
May 16th, 2000 05:09
Hiroto Sekine, http://www.all.co.nz/support/jpspell.htm
With IE5.x, the following sample code enables selective document area
printout utilizing beforeprint, afterprint event, document.style
attribute.(The code below is showed as prototyping, active page is
below)
active sample page: http://www.all.co.nz/support/jpspell.htm
=======================[JavaScript]=================
var F = document.all;
var saveBC;
var saveFC;
var goOrgShow = new Array();
function beforePrint(){
var x, y, section, ans1, ans2, coll;
with(oBody.currentStyle){
saveBC = backgroundColor;
saveFC = color;
}
with(oBody.style){
backgroundColor = 'white';
color = 'black';
}
coll = F.tags( 'legend' );
ans1 = window.confirm('Click [OK] to print entire page. Click
[CANCEL] to select print section.');
for (var i=0; i<coll.length; i++){
x = F[ 'LEG' + i.toString() ];
if (x != null){
y = F[ 'FLD' + i.toString() ];
if (!ans1){
section = x.innerText;
ans2 = window.confirm('Click [OK]
to print ' + section + '. Click [CANCEL] to skip.');
}
if (y){
goOrgShow[i] = y.style.display;
if (!ans1){
y.style.display = (!
ans2) ? 'none' : '';
} else {
y.style.display = '';
}
}
}
}
}
function afterPrint(){
var x, y;
with(oBody.style){
backgroundColor = saveBC;
color = saveFC;
}
var coll = F.tags( 'legend' );
for (var i=0; i<coll.length; i++){
x = F[ 'LEG' + i.toString() ];
if (x != null){
y = F[ 'FLD' + i.toString() ];
if (y){
y.style.display = goOrgShow[i];
}
}
}
}
=================[ HTML page ]================================
<body OnBeforePrint="beforePrint();" OnAfterPrint="afterPrint();"
id="oBody">
<fieldset style="display:none;" id="FLD0">
<legend id="LEG0"><< Title 0 >></legend>
AAAAAAAAAAAAAAAAAA
</fieldset>
<fieldset style="display:none;" id="FLD1">
<legend id="LEG0"><< Title 1 >></legend>
BBBBBBBBBBBBBBBBBB
</fieldset>
<fieldset style="display:none;" id="FLDn">
<legend id="LEGn"><< Title n >></legend>
NNNNNNNNNNNNNNNNNNNNNNN
</fieldset>