Print

Calling the print method has the same effect as choosing Print from the Microsoft? Internet Explorer File menu. The print method activates the Print dialog box, prompting the user to change print settings. When the user clicks the OK button, the following sequence of events occurs:

The onbeforeprint event fires.
The document prints.
The onafterprint event fires.

The onbeforeprint and onafterprint events are particularly useful when not all the information on the page is visible at all times. Use the onbeforeprint to modify the document to make all the information on the page visible for printing. To return the document to its original state, use the onafterprint event.


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值