DHTML Events
Fires on the object immediately after its associated document prints.
Inline HTML |
<element onafterprint = "handler" ... > |
All platforms |
Event property |
object.onafterprint = handler |
ECMA-262 Language Specification |
Named script |
<script FOR=object EVENT = onafterprint> |
Internet Explorer® only |
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 in conjunction with the onbeforeprint event. Whereas the onbeforeprint event gives the Web author an opportunity to make changes to the document just before it prints, the onafterprint event provides a means to undo those changes, reverting the document back to its pre-print state.
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
altKey |
Retrieves the current state of the ALT key. |
button |
Retrieves which mouse button, if any, is pressed. |
cancelBubble |
Sets or retrieves whether the current event should bubble up the hierarchy of event handlers. |
clientX |
Retrieves the x-coordinate of the position of the cursor when the mouse is clicked, relative to the size of the client area of the window but excluding window decorations or scroll bars. |
clientX |
Returns the y-coordinate of the position of the cursor when the mouse is clicked, relative to the size of the client area of the window but excluding window decorations or scroll bars. |
ctrlKey |
Retrieves the state of the CTRL key. |
returnValue |
Sets or retrieves the return value from the event. |
screenX |
Retrieves the horizontal position of the mouse, in pixels, relative to the user's screen. |
screenY |
Retrieves the vertical position of the mouse, in pixels, relative to the user's screen. |
shiftKey |
Retrieves the state of the SHIFT key. |
srcElement |
Retrieves the object that fired the event. |
type |
Retrieves the event name from the event object. |
x |
Returns the horizontal position of the mouse when the event fires. |
y |
Returns the vertical position of the mouse when the event fires. |
The following example demonstrates how the onafterprint event can be used to bring the document back to its pre-print state. In this case, since the onbeforeprint event handler made all currently hidden sections of the page visible for printing purposes, the onafterprint event is used to set those sections back to hidden.
Sample Code
function window.onbeforeprint() {
var coll = document.all.tags("DIV");
if (coll!=null) {
// check for class = "collapsed" and set to "expanded" for printing
for (i=0; i<coll.length; i++)
if (coll[i].className == "collapsed") {
coll[i].className = "expanded";
// flag changed class
coll[i].bExpandedForPrinting = true;
}
else if (coll[i].className == "expanded")
coll[i].bExpandedForPrinting = false;
}
}
function window.onafterprint() {
var coll = document.all.tags("DIV");
if (coll!=null) {
/* check for class = "expanded" and flagged for printing
then reset to "collapsed" */
for (i=0; i < coll.length; i++)
if ((coll[i].className == "expanded") &&
(coll[i].bExpandedForPrinting)){
coll[i].className = "collapsed";
coll[i].bExpandedForPrinting = false;
}
}
}
window, BODY, FRAMESET
onbeforeprint, print
|
|