onafterprint Event

MS Office DHTML, HTML & CSS

 
Click to return to the DHTML, HTML & CSS home page    
onabort Event     onafterupdate Event     DHTML Events    

onafterprint Event


Fires on the object immediately after its associated document prints.

Syntax

Inline HTML <ELEMENT onafterprint = "handler" ... > All platforms
Event property object.onafterprint = handler JScript (compatible with ECMA 262 language specification) only
Named script <SCRIPT FOR = object EVENT = onafterprint> Internet Explorer only

Remarks

Bubbles No
Cancels No
To invoke
  • Choose Print from the File menu in Internet Explorer.
  • Press CTRL + P.
  • Right-click anywhere on a page, and choose Print.
  • Right-click on a link on a page, and choose Print.
  • From Windows Explorer, select an .htm file, and then choose Print from the File menu.
  • From Windows Explorer, right-click on an .htm file, and then choose Print.
Default Action None

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

Event Object Properties

Although event handlers in the document object model do not receive parameters directly, the handler can query the event object for data.

Event Object Properties

altKeyRetrieves the current state of the ALT key.
buttonRetrieves which mouse button, if any, is pressed.
cancelBubbleSets or retrieves whether the current event should bubble up the hierarchy of event handlers.
clientXRetrieves the x-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars.
clientYRetrieves the y-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars.
ctrlKeyRetrieves the state of the CTRL key.
returnValueSets or retrieves the return value from the event.
screenXRetrieves the horizontal position of the mouse, in pixels, relative to the user's screen.
screenYRetrieves the vertical position of the mouse, in pixels, relative to the user's screen.
shiftKeyRetrieves the state of the SHIFT key.
srcElementRetrieves the object that fired the event.
typeRetrieves the event name from the event object.
xRetrieves the x-coordinate of the mouse cursor relative to the parent element.
yRetrieves the y-coordinate of the mouse cursor relative to the parent element.

Example

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 page visible for printing, the onafterprint event sets those sections back to hidden.

Sample Code

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

This feature requires Microsoft Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
window, BODY, FRAMESET

See Also

onbeforeprint, print


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.