js控制打印分页

<html>

<title>JS 分页批量打印解决方案(只支持IE)</title>

<script language="javascript">         

 function printWithAlert() {       

 document.all.WebBrowser.ExecWB(6,1);    

 }     

 function printWithoutAlert() {      

   document.all.WebBrowser.ExecWB(6,6);     

 }   

 function printSetup() {       

 document.all.WebBrowser.ExecWB(8,1);     

 }    

 function printPrieview() {       

 document.all.WebBrowser.ExecWB(7,1);     

 }     

function printImmediately() {       

document.all.WebBrowser.ExecWB(6,6);      

 window.close();     

 }      

</script>

<OBJECT  id=WebBrowser  classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 style="display:none">

</OBJECT>

<style media=print> 

.Noprint{display:none;}  .PageNext{page-break-after: always;} 

</style>

<table align="center" class=NOPRINT>

  <tr>

    <td align="center"><BUTTON title=打印 onclick=printWithAlert()>打印</BUTTON>

      <BUTTON title=直接打印 onclick=printWithoutAlert()>直接打印</BUTTON>

      <input type=button value="打印设置" onClick="printSetup()" >

      <button onclick ='printPrieview()' title='打印预览...' >打印预览</button></td>

  </tr>

</table>

<div  class=NOPRINT> 以下为打印区:<br>

</div>

<hr size=1 noshadow color=black  class=NOPRINT >

<table class="PageNext" >

  <tr>

    <td colspan=2>

 第一页的内容

 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    </td>

  </tr>

</table>

<hr size=1 noshadow color=black  class=NOPRINT >

<div class="PageNext">

第二页内容

 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

</div>

<hr size=1 noshadow color=black  class=NOPRINT >

第三页内容

</html> 

   现在就实现了基本的web打印,需要注意的情况如下: 
   必须将ie的internet选项的安全设置中对于没有标记为安全的ActiveX控件进行js控制打印分页设置成提示或者启用,否则会报错,导致不可用。 

   本文转载于http://heisetoufa.iteye.com/blog/815067

你可能感兴趣的:(js)