使用IE的打印功能(个人总结)

<script type="text/javascript" language="javascript">

        var hkey_root,hkey_path,hkey_key

        hkey_root="HKEY_CURRENT_USER"

        hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"

       

        //设置网页打印的页眉页脚为空

        function pagesetup_null(){

        try{

        var RegWsh = new ActiveXObject("WScript.Shell")

        hkey_key="header"

        RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")

        hkey_key="footer"

        RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")

        }catch(e){}

        }

        function printPage()

        {

            //页面打印

            pagesetup_null()

            document.getElementById('ButPrint').style.visibility = 'hidden' ;

            document.getElementById('ButSetup').style.visibility = 'hidden' ;

            document.getElementById('ButShow').style.visibility = 'hidden' ;

            document.getElementById('ButShows').style.visibility = 'hidden' ;

            

            document.getElementById('fy').style.visibility='hidden';

           

            var newWin = window.open('printer','','');

            var titleHTML = document.getElementById("divshow").innerHTML;

            newWin.document.write(titleHTML);

            newWin.document.location.reload();

            wb.ExecWB(6,1);

            newWin.close();

            document.getElementById('fy').style.visibility='visible';

            document.getElementById('ButPrint').style.visibility = 'visible';

            document.getElementById('ButSetup').style.visibility = 'visible' ;

            document.getElementById('ButShow').style.visibility = 'visible' ;

            document.getElementById('ButShows').style.visibility = 'visible' ;          

        }

    function   printsetup()

    {    

        //   打印页面设置  

          pagesetup_null() 

            document.getElementById('ButPrint').style.visibility = 'hidden' ;

            document.getElementById('ButSetup').style.visibility = 'hidden' ;

            document.getElementById('ButShow').style.visibility = 'hidden' ;

            document.getElementById('ButShows').style.visibility = 'hidden' ;

            document.getElementById('fy').style.visibility='hidden';

            pagesetup_null();

            wb.ExecWB(8,1); 

            document.getElementById('fy').style.visibility='visible'; 

            document.getElementById('ButPrint').style.visibility = 'visible';

            document.getElementById('ButSetup').style.visibility = 'visible' ;

            document.getElementById('ButShow').style.visibility = 'visible' ;

            document.getElementById('ButShows').style.visibility = 'visible' ;

    }

    function   printpreview()

    {    

        //   打印页面预览 

          pagesetup_null();

            pagesetup_null();

            var newWin = window.open('','','');

            var titleHTML = document.getElementById("divshow").innerHTML;

            newWin.document.write(titleHTML);

            newWin.document.location.reload();

            wb.ExecWB(7,1);

            newWin.close(); 

    }

</script>

     <style type="text/css">

    @media print { .noprint {display:none} }   

    @media print{

    .TextLine1

        {

         border-top-width: 0px;

         border-right-width: 0px;

         border-bottom-width: 0px;

         border-left-width: 0px;

         border-top-style: none;

         border-right-style: none;

         border-bottom-style: solid;

         border-left-style: none;

         border-top-color: #000000;

         border-right-color: #000000;

         border-bottom-color: #000000;

         border-left-color: #000000;

        }

    }

   .ta{ border-bottom-style:none;text-align:center;}

   .t{display:table-header-group;font-weight:bold;}

   .PageNext{page-break-after:always;}

   .f{display:table-footer-group; border:none;}

    .a{border-right:none; border-bottom:none;}

    .b{border-right:none;}

   </style>

 

 <object classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" id="wb" name="wb" width="0"></object>

 

<input id="ButShow" name="ButShow" type="button" value="预览" οnclick="printpreview();" />

            <input id="ButSetup" name="ButSetup" type="button" value="页面设置" οnclick="javascript:printsetup();" />

            <input id="ButPrint" name="ButPrint" type="button" value="打印" οnclick="printPage();" />

            <input id="ButShows" name="ButShows" type="button" value="关闭" οnclick="javascript:window.close();" />

 

需要修改IE浏览器的功能。

步骤:“工具”---Internet选项---》“安全”》“自定义级别”---》启用“对未标记为可安全执行脚本的ActiveX控件初始化并执行脚本”。

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
IE下页面打印控件 类似于ScriptX控件,但本控件可免费使用 控件使用OCX技术,使控件加载到IE浏览器中 首次使用需要用户加载Activex控件,以后将自动加载运行 控件功能: 1.屏蔽IE打印时出现的打印设置框。 2.自动设置各打印控制参数。 3.实现自动打印使用方法 控件的ID为clsid:AE1A309B-6FFA-4FCF-B07F-CB97FFD56B1B 使用Object标签包裹即可。 如 <OBJECT ID="TestAX" classid="clsid:AE1A309B-6FFA-4FCF-B07F-CB97FFD56B1B" codebase="IEprint.ocx#version=" width=0 height=0 align=center hspace=0 vspace=0 ></OBJECT> 使用Javascript或VBScript程序进行调用 使用使,先得到打印控件Object对象实例如 a=document.getElementById("TestAX"); 参数内容 接着对a进行操作即可 a.Mar_left=0.0075; //左边界 a.Mar_Top=0.0075; //上边界 a.Mar_Right=0.0075; //右边界 a.Mar_Bottom=0.0075; //下边界 a.Orientation="纵向";//打印方向 a.Paper_Size="Folio"; //纸张大小 a.Header_Html="Headeraaaaaaaa"; //头部标注 a.Footer_Html="Footerssssssss"; //尾部标注 a.ApplySetup(); //应用上面的设置 函数方法 a.PrintWithOutSetup(); //无需设置即打印内容 a.PrintWithOutSetupPrintWithOutByID("cnnb"); //打印除ID为cnnb的其他内容。即过滤id为cnnb的所有内容 a.PrintWithOutSetupPrintByID("163");//打印id为163的内容。即过滤id为163以外的所有内容 a.PrintWithSetup(); //有设置选项的打印 a.PrintPreView();//打印预览 对本控件有建议的可以联系我,一般隐身存在。。。 chatop QQ948905
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值