JavaScript的打印技术体会 (转)

来源:互联网 发布:淘宝排名突然没有了 编辑:程序博客网 时间:2024/05/21 21:44
特定内容的部分打印技术
1.打印某个frame的内容(frameB)
    <html>
    <frameset rows="20%,*">
        <frame SRC="framea.htm" name="FrameA" noresize>
        <frame SRC="frameb.htm" name="FrameB" noresize>
    <noframes>
    <body>
    </body>
    </noframes>
    </frameset>
    </html>

frameA中添加
    <input type="button" value="Print the other frame" onclick="parent.frameB.print();">

2.打印某个对象中的内容,如textbox中的内容
    frameA:
    <html><head>
     </head>
    <body>
    <form name="formB" action="javascript:window.print()">
        <input type="text" name="textboxb" size="12" value="Print Me">
    </form>
    </body></html>
frameB:
    <html><head>
    <script>
    function printotherframe()
    {
        parent.FrameB.formB.textboxb.focus()
        parent.FrameB.formB.submit()
    }
    </script>
    </head><body>
        <form name="formA"><input type="button" value="Print the other frame" onclick="printotherframe()">
    </body></html>

3.打印非当前页
技术同上,只是在frame显示中动一点点骗人的手脚
    <frameset rows="100%,*">
    <frame src="controlpage.html">
    <frame src="pagetoprint.html">
    </frameset>

    <script language="JavaScript"><!--
        if (window.print)
        document.write('<form><input type="button" value="Print" onClick="parent.frames[1].focus();parent.frames[1].print()"><//form>');
    //--></script>

4.统一页眉页脚
    <script language="Javascript"><!--
    function doprint() {
      //save existing user's info
      var h = factory.printing.header;
      var f = factory.printing.footer;
      //hide the button
      document.all("printbtn").style.visibility = 'hidden';
      //set header and footer to blank
      factory.printing.header = "";
      factory.printing.footer = "";
      //print page without prompt
      factory.DoPrint(false);
      //restore user's info
      factory.printing.header = h;
      factory.printing.footer = f;
      //show the print button
      document.all("printbtn").style.visibility = 'visible';
    }
    //--></script>
    <body>
    <br><br><br>
    <object id=factory style="display:none"  classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext codebase="ScriptX.cab#Version=5,0,4,185">
    </object>
    <br><br>
    <div id="printbtn"><input name=idPrint type=button value="Print the letter" onclick="doprint()"></div>
    </body>

5.打开新窗口并自动打印
    <object id=WBControl width=0 height=0 classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2></object>
    <script language=VBScript><!-- //
     Sub VBPrint() On Error Resume Next
        WBControl.ExecWB 6,1    '7,2在不少文章中都有提到,这里就不多说了。
     End Sub
    //--></script>

    <script language=JavaScript><!-- //
    if (window.print) self.print();
    else if (navigator.appName.indexOf('Microsoft') !=-1) VBPrint()
    setTimeout('self.close()',3000);    '看代码相信大家都能明白。如果有不明白的欢迎留言
    //--></script>
html中
    <form>
    <input type="button" value="Print Price List" onClick="window.open('pricelist.html','newwin');">
    </form>

原创粉丝点击