• 首页 >web前端 >js教程 >JavaScript 实现網頁打印處理_javascript技巧

    JavaScript 实现網頁打印處理_javascript技巧

    WBOY
    WBOY原创
    2016-05-16 19:14:22954浏览

    1、控制"纵打"、 横打”和“页面的边距。 
    (1)<script> <BR>function SetPrintSettings() { <br><br> factory.printing.SetMarginMeasure(2) // measure margins in inches <BR> factory.SetPageRange(false, 1, 3) // need pages from 1 to 3 <BR> factory.printing.printer = "HP DeskJet 870C" <BR> factory.printing.copies = 2 <BR> factory.printing.collate = true <BR> factory.printing.paperSize = "A4" <BR> factory.printing.paperSource = "Manual feed" <BR> factory.printing.header = "This is MeadCo" <BR> factory.printing.footer = "Advanced Printing by ScriptX" <BR> factory.printing.portrait = false <BR> factory.printing.leftMargin = 1.0 <BR> factory.printing.topMargin = 1.0 <BR> factory.printing.rightMargin = 1.0 <BR> factory.printing.bottomMargin = 1.0 <BR>} <BR></script> 

    2) 
    <script> <BR>  function printsetup(){ <BR>  // 打印页面设置 <BR>  wb.execwb(8,1); <BR>  } <BR>  function printpreview(){ <BR>  // 打印页面预览      <BR>  wb.execwb(7,1);   } <BR>  function printit() <BR>  { <BR>  if (confirm('确定打印吗?')) { <BR>  wb.execwb(6,6) <BR>  } <BR>  } <BR>  </script> 
     

     
     
     &#111nclick="&#106avascript:printit()"> 
    #111nclick="&#106avascript:printsetup();"> 




    &#111nclick="&#106avascript:printpreview();"> 

    &#111nclick="&#106avascript:window.close();"> 

    WebBrowser.ExecWB(1,1) 打开 
    Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口 
    Web.ExecWB(4,1) 保存网页 
    Web.ExecWB(6,1) 打印 
    Web.ExecWB(7,1) 打印预览 
    Web.ExecWB(8,1) 打印页面设置 
    Web.ExecWB(10,1) 查看页面属性 
    Web.ExecWB(15,1) 好像是撤销,有待确认 
    Web.ExecWB(17,1) 全选 
    Web.ExecWB(22,1) 刷新 
    Web.ExecWB(45,1) 关闭窗体无提示 


    2、分页打印 
     
     
     
     
     
     

     
     
     
     
     

    3、ASP页面打印时如何去掉页面底部的路径和顶端的页码编号 
    (1)ie的文件-〉页面设置-〉讲里面的页眉和页脚里面的东西都去掉,打印就不出来了。 
    (2) 
     
     New Document  
     
     
    <script> <BR>dim hkey_root,hkey_path,hkey_key <BR>hkey_root="HKEY_CURRENT_USER" <BR>hkey_path="\Software\Microsoft\Internet Explorer\PageSetup" <BR>'//设置网页打印的页眉页脚为空 <BR>function pagesetup_null() <BR>  on error resume next <BR>  Set RegWsh = CreateObject("WScript.Shell") <BR>  hkey_key="\header"   <BR>  RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"" <BR>  hkey_key="\footer" <BR>  RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"" <BR>end function <BR>'//设置网页打印的页眉页脚为默认值 <BR>function pagesetup_default() <BR>  on error resume next <BR>  Set RegWsh = CreateObject("WScript.Shell") <BR>  hkey_key="\header"   <BR>  RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P" <BR>  hkey_key="\footer" <BR>  RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&u&b&d" <BR>end function <BR></script> 
     

     

     

     

     

     

     

     
     
     

     
     
     
    4、浮动帧打印 
    <script> <BR>function button1_&#111nclick() { <BR>  var odoc=window.iframe1.document; <BR>  var r=odoc.body.createTextRange(); <BR>  var stxt=r.htmlText; <BR>  alert(stxt) <BR>  var pwin=window.open("","print"); <BR>  pwin.document.write(stxt); <BR>  pwin.print(); <BR>} <BR></script> 
    4、用FileSystem组件实现WEB应用中的本地特定打印 
    <script> <BR>function print_&#111nclick //打印函数 <BR>dim label <BR>label=document.printinfo.label.&#118alue //获得HTML页面的数据 <BR>set objfs=CreateObject("Scripting.FileSystemObject") //创建FileSystem组件对象的实例 <BR>set objprinter=objfs.CreateTextFile ("LPT1:",true) //建立与打印机的连接 <BR>objprinter.Writeline("__________________________________") //输出打印的内容 <BR>objprinter.Writeline("| |") <BR>objprinter.Writeline("| 您打印的数据是:"&label& " |”) <BR>objprinter.Writeline("| |") <BR>objprinter.Writeline("|_________________________________|") <BR>objprinter.close //断开与打印机的连接 <BR>set objprinter=nothing <BR>set objfs=nothing // 关闭FileSystem组件对象 <BR>end function <BR></script> 
    服务器端脚本: 
    set conn=server.CreateObject ("adodb.connection") 
    conn.Open "DSN=name;UID=XXXX;PWD=XXXX;" 
    set rs=server.CreateObject("adodb.recordset") 
    rs.Open(“select ……”),conn,1,1 
    ……….%> //与数据库进行交互 
    HTML页面编码: 
     
    ……… 
     
    >" id=print name=print > //调用打印函数 
    > //保存服务器端传来的数据 
    ……… 


    声明:
    本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn