EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

beforeprint | onbeforeprint event

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

Syntax

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

Event information

SynchronousNo
BubblesNo
CancelableNo

Event handler parameters

pEvtObj [in]

Type: IHTMLEventObj

Standards information

There are no standards that apply here.

Remarks

Use this event to modify the document just before it prints or previews for printing. In most cases it is used to make all the information on the document visible just before printing.

Use the event in conjunction with the onafterprint event to undo the changes made to the document in the onbeforeprint event.

Prints the document associated with the object for which the event is specified.

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 choose Print from the File menu.
  • From Windows Explorer, right-click an .htm file and choose Print.

The pEvtObj parameter is required for the following interfaces:

Examples

This example uses the onbeforeprint to make all hidden sections of the document visible just before the document prints. The onafterprint event is processed after the document prints to return the document to its original state.

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


function window.onbeforeprint()
{
    // Walk through all the elements in the document 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;
   }
}
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;
         }
   }
}

See also

body
frameSet
window
Reference
onafterprint
print

 

 

Afficher:
© 2014 Microsoft. Tous droits réservés.