<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 5,  comments - 7,  trackbacks - 0
    對JS的打印方法總結一下,方便日后查閱。

    一.用JS自帶函數打印

    直接調用
    Java代碼 復制代碼
    1. <a href="javascript:window.print();">打印</a>  


    二.IEWebBrowser組件

    介紹

    http://support.microsoft.com/default.aspx?scid=kb%3BEN-US%3BQ267240#top
    http://support.microsoft.com/kb/q247671/#appliesto

    Java代碼 復制代碼
    1. <OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>    
    2. <input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打開>   
    3. <input name=Button onClick=document.all.WebBrowser.ExecWB(2,1) type=button value=關閉所有>   
    4. <input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存為>    
    5. <input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印>   
    6. <input name=Button onClick=document.all.WebBrowser.ExecWB(6,6) type=button value=直接打印>   
    7. <input name=Button onClick=document.all.WebBrowser.ExecWB(7,1) type=button value=打印預覽>   
    8. <input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=頁面設置>   
    9. <input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=屬性>   
    10. <input name=Button onClick=document.all.WebBrowser.ExecWB(17,1) type=button value=全選>   
    11. <input name=Button onClick=document.all.WebBrowser.ExecWB(22,1) type=button value=刷新>   
    12. <input name=Button onClick=document.all.WebBrowser.ExecWB(45,1) type=button value=關閉>  


    三.使用ScriptX.cab控件

    1.下載ScriptX.cab控件

    官網http://www.meadroid.com/scriptx/index.asp

    2.使用object元素,修改codebase,classid的值

    這里調用控件ScriptX.cab
    Java代碼 復制代碼
    1. <OBJECT id="factory" style="DISPLAY: none" codeBase="${rootUrl}js/smsx.cab#VVersion=6,3,435,20"  classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext></OBJECT>  


    這段代碼用來加載cab文件,clsid和codebase必須要和你下載的cab中的信息對應,否則組件會加載錯誤,這兩項其實不難找,只要你用winrar打開你下載的cab文件,然后找到擴展名是.inf的文件,然后打開之,就能看到了。

    3.調用控件腳本

    Print.js文件
    Java代碼 復制代碼
    1. function setPrintBase(headerText,footerText,rootUrl) {   
    2.   
    3.     // -- advanced features  ,未曾使用過,有待確認。   
    4.   
    5.         //factory.printing.SetMarginMeasure(2); // measure margins in inches   
    6.   
    7.         //factory.SetPageRange(false, 1, 3);// need pages from 1 to 3   
    8.   
    9.         //factory.printing.printer = "HP DeskJet 870C";   
    10.   
    11.         //factory.printing.copies = 2;   
    12.   
    13.         //factory.printing.collate = true;   
    14.   
    15.         //factory.printing.paperSize = "A4";   
    16.   
    17.         //factory.printing.paperSource = "Manual feed"   
    18.   
    19.     var header = (headerText==null||headerText=="")?'默認頁眉':headerText;   
    20.   
    21.     var footer = (footerText==null||footerText=="")?'默認頁角':footerText;   
    22.   
    23.   factory.printing.header = "&b"+header+"&b" ;   
    24.   
    25.   factory.printing.footer = "&b"+footer;   
    26.   
    27.   factory.printing.portrait = true;   
    28.   
    29.   factory.printing.leftMargin =10.00;   
    30.   
    31.   factory.printing.topMargin =10.00;   
    32.   
    33.   factory.printing.rightMargin =10.00;   
    34.   
    35.   factory.printing.bottomMargin =10.00;   
    36.   
    37. }  



    例子
    Java代碼 復制代碼
    1. <%@ page contentType="text/html;charset=GBK"%>   
    2.   
    3. <html>   
    4. <head>   
    5. <meta http-equiv="imagetoolbar" content="no">   
    6. <script language="javascript" src="print.js"></script>   
    7. <style media="print">   
    8. .Noprint   {DISPLAY:   none;}   
    9. </style>   
    10. <title>打印測試</title>   
    11. </head>   
    12. <OBJECT id="factory" style="DISPLAY: none" codeBase="smsx.cab#VVersion=6,3,435,20"  classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext></OBJECT>   
    13.   
    14. <script defer>   
    15. function window.onload() {      
    16. setPrintBase('頁眉','頁腳');   
    17. }   
    18. </script>   
    19. <body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">   
    20. <center class="Noprint">   
    21.  <input type=button value="打印" onclick="factory.printing.Print(true)">    
    22. <input type=button value="頁面設置" onclick="factory.printing.PageSetup()">    
    23.  <input type=button value="打印預覽" onclick="factory.printing.Preview()">              
    24. <input type="button" value="關閉" onclick="window.close();">   
    25. </center>   
    26.    <center>   
    27.       <table width="100%" border="0" cellpadding="0" cellspacing="0">   
    28.           <tr><td align="center"><b>內容</b></td></tr>   
    29.        </table>   
    30.     </center>   
    31. </body>   
    32. </html>  


    四.對比

    1.Window.print調用方便,但功能簡單

    2.功能更強大,但使用IEWebBrowser有時會報JS沒有權限的錯誤。

    3.ScriptX控件功能也比較強大,目前在使用這種方式。
    posted on 2008-11-24 23:51 Vincent-chen 閱讀(223) 評論(0)  編輯  收藏 所屬分類: JavaScript
    主站蜘蛛池模板: 亚洲综合校园春色| 亚洲国产日韩在线一区| 亚洲一级片免费看| 亚洲成av人片不卡无码久久 | 久久久国产精品亚洲一区| 在线观看免费视频网站色| 国产亚洲真人做受在线观看| 97在线视频免费公开视频| 亚洲va中文字幕无码久久不卡| 十八禁在线观看视频播放免费| 亚洲日韩aⅴ在线视频| 免费看一区二区三区四区| 亚洲国产精品成人久久| 亚洲网站免费观看| 亚洲国产视频久久| 免费在线观看你懂的| 国产黄色免费观看| 亚洲视频在线视频| 最近高清国语中文在线观看免费| 亚洲欧洲av综合色无码| 亚洲精品乱码久久久久久蜜桃| 99re8这里有精品热视频免费| 亚洲一区精品中文字幕| 成人免费在线视频| 成年大片免费高清在线看黄| 亚洲精品高清国产一线久久| 99精品视频免费在线观看| 亚洲色无码专区一区| 国产成人亚洲综合| 日本最新免费网站| 国产亚洲精品免费| 亚洲国产精品无码av| 成年在线网站免费观看无广告| 人人公开免费超级碰碰碰视频 | 亚洲成人高清在线观看| 国产精品国产免费无码专区不卡 | 99在线免费观看视频| 久久精品国产亚洲av天美18| 亚洲国产成人片在线观看无码| 免费精品人在线二线三线区别| 一区在线免费观看|