afterprint | onafterprint event

Fires on the object immediately after its associated document prints or previews for printing.

Syntax

HTML Attribute <element onafterprint = "handler(event)">
Event Property object.onafterprint = handler;
attachEvent Method object.attachEvent("onafterprint", handler)
addEventListener Method object.addEventListener("afterprint", handler, useCapture)

Event information

SynchronousNo
BubblesNo
CancelableNo

Event handler parameters

pEvtObj [in]

Type: IHTMLEventObj

Standards information

There are no standards that apply here.

Remarks

This event is usually used with the onbeforeprint event. Use the onbeforeprint event to make changes to the document just before it prints or previews for printing. Use the onafterprint event to undo those changes, reverting the document back to its pre-print or pre-preview state.

None

To invoke this event, do one of the following:

  • Choose Print or Print Preview from the File menu.
  • Press CTRL+P.
  • Right-click anywhere on a document, and choose Print.
  • Right-click a link on a document, and choose Print.
  • From Windows Explorer, select an .htm file, and then choose Print from the File menu.
  • From Windows Explorer, right-click an .htm file, and then choose Print.

The pEvtObj parameter is required for the following interfaces:

Examples

This example uses the onafterprint event to return the document to its pre-print state. In this case, because the onbeforeprint event handler makes all currently hidden sections of the document visible for printing, the onafterprint event sets those sections back to hidden.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onbeforeprint.htm


function window.onafterprint()
{
    // Walk through all the elements in the doc with CLASS="expanded"
    // and set it to "collapsed" if expanded just for 
    // printing.
   var coll = document.all.tags("DIV");
   if (coll!=null)
   {
      for (i=0; i<coll.length; i++) 
	     if ((coll[i].className == "expanded") &&
		     (coll[i].bExpandedForPrinting))
		 {  
		   coll[i].className = "collapsed";
		   coll[i].bExpandedForPrinting = false;
		 }
   }
}
function window.onbeforeprint()
{
    // Walk through all the elements in the doc with CLASS="collapsed"
    // and set it to "expanded" just for printing.
   var coll = document.all.tags("DIV");
   if (coll!=null)
   {
      for (i=0; i<coll.length; i++) 
	     if (coll[i].className == "collapsed")
		 {  
		   coll[i].className = "expanded";
		   
		// After printing, make sure to set
		// CLASS="collapsed" only for those that were
		// expanded just for printing.
		   coll[i].bExpandedForPrinting = true;
		 }
		 else if (coll[i].className == "expanded")
		    coll[i].bExpandedForPrinting = false;
   }
}

See also

body
frameSet
window
Reference
onbeforeprint
print

 

 

Show:
© 2014 Microsoft. All rights reserved.