This page is In Progress

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

afterprint

Overview Table

Synchronous No
Bubbles No
Target dom/Element
Cancelable No
Default action ?
## 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.

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;
   }
}

View live example

Notes

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.

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:

  • HTMLAnchorEvents2
  • HTMLAreaEvents2
  • HTMLButtonElementEvents2
  • HTMLControlElementEvents2
  • HTMLDocumentEvents2
  • HTMLElementEvents2
  • HTMLFormElementEvents2
  • HTMLImgEvents2
  • HTMLFrameSiteEvents2
  • HTMLInputFileElementEvents2
  • HTMLInputImageEvents2
  • HTMLInputTextElementEvents2
  • HTMLLabelEvents2
  • HTMLLinkElementEvents2
  • HTMLMapEvents2
  • HTMLMarqueeElementEvents2
  • HTMLObjectElementEvents2
  • HTMLOptionButtonElementEvents2
  • HTMLScriptEvents2
  • HTMLSelectElementEvents2
  • HTMLStyleElementEvents2
  • HTMLTableEvents2
  • HTMLTextContainerEvents2
  • HTMLWindowEvents2

Syntax

Standards information

There are no standards that apply here.

Event handler parameters

pEvtObj [in]
Type: ****IHTMLEventObj****

See also

Related pages

  • window
  • body
  • frameSet
  • Reference
  • onbeforeprintonbeforeprint
  • print

Attributions