JavaScript的列印技術體會

來源:互聯網
上載者:User
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
  // -- advanced features 
  factory.printing.SetMarginMeasure(2) // measure margins in inches 
  factory.SetPageRange(false, 1, 3) // need pages from 1 to 3 
  factory.printing.printer = "HP DeskJet 870C" 
  factory.printing.copies = 2 
  factory.printing.collate = true 
  factory.printing.paperSize = "A4" 
  factory.printing.paperSource = "Manual feed" //付費才能用。

      factory.printing.header = "";
      factory.printing.footer = "";
      factory.printing.portrait=true; // factory.printing.portrait = false; 橫,縱紙張設定
      //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>

//設定在body onload中時,系統將自動回復原來的列印設定

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.