zoukankan      html  css  js  c++  java
  • JavaScript打印

    <HTML>
    <HEAD>
    <TITLE>JavaScript利用IE内置打印控件IEWebBrowser进行打印/打印页面设置/打印预览/控制分页打印</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=gbk" />
    <SCRIPT type="text/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 pagesetup_default(){
    try{
    var RegWsh = new ActiveXObject("WScript.Shell");
    hkey_key="\header" ;
    RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P");
    hkey_key="\footer";
    RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d");
    }catch(e){}
    }
    function printsetup(){ 
     wb.execwb(8,1); // 打印页面设置
    }
    function printpreview(){ 
     wb.execwb(7,1);// 打印页面预览
    }
    function printit() {
     if (confirm('确定打印吗?')) {
      wb.execwb(6,1);
     }
    }
    </SCRIPT>
    <!--media=print 这个属性说明可以在打印时有效-->
    <!--希望打印时不显示的内容设置class="Noprint"样式-->
    <!--希望人为设置分页的位置设置class="PageNext"样式-->
    <style media="print">
    <!--
    .Noprint{display:none;}
    .PageNext{page-break-after:always;}
    -->
    </style>
    <style type="text/css">
    <!--
    .STYLE1 {font-size: 12px}
    -->
    </style>
    </HEAD>
    <BODY>
    <!--IE内置打印控件IEWebBrowser-->
    <OBJECT id=wb height=0 width=0 classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 name=wb></OBJECT>
    <form>
    <table width="600" border="1" align="center" cellpadding="0" cellspacing="0" class="STYLE1">
      <tr>
        <td height="17" colspan="3" bgcolor="#0099CC">&gt;&gt;监控信息&gt;&gt;</td>
      </tr>
      <tr>
        <td height="27" align="center" bgcolor="#C6C4DF">序号</td>
        <td align="center" bgcolor="#C6C4DF">学校代码</td>
        <td align="center" bgcolor="#C6C4DF">设备状态</td>
      </tr>
        <tr>
        <td height="17" align="center">1</td>
        <td height="17" align="center">1001</td>
        <td height="17" align="center">正常</td>
      </tr>
      <tr class="PageNext"><!--希望人为设置分页的位置设置class="PageNext"样式-->
        <td height="17" align="center">2</td>
        <td height="17" align="center">1002</td>
        <td height="17" align="center">正常</td>
      </tr>
      <tr>
        <td height="17" align="center">3</td>
        <td height="17" align="center">1003</td>
        <td height="17" align="center">正常</td>
      </tr>
    </table>
    <DIV align=center>
    <!--希望打印时不显示的内容设置class="Noprint"样式-->
    <INPUT onclick=javascript:printit() type=button value=打印 name=button_print class="Noprint"/>
    <INPUT onclick=javascript:printsetup(); type=button value=打印页面设置 name=button_setup class="Noprint" />
    <INPUT onclick=javascript:printpreview(); type=button value=打印预览 name=button_show class="Noprint" />
    <input type="button" value="清空页码" onclick=javascript:pagesetup_null() class="Noprint">
    <input type="button" value="恢复页码" onclick=javascript:pagesetup_default() class="Noprint">
    </DIV>
    </form>
    </BODY>
    </HTML>

  • 相关阅读:
    DedeCMS的arclist循环中判断第一个元素并添加class样式
    PC 浏览器伪装移动(微信)User-Agent
    DedeCMS后台无法保存中文字符
    java spring boot 定时器
    java spring boot 部署redis
    java spring boot 打包方法
    java spring boot返回json的写法
    关于java idea 创建spring boot没有下载依赖的解决方案
    java和golang并发测试
    php转java 系列2 Spring boo 链接数据库jdbc
  • 原文地址:https://www.cnblogs.com/liyuxin/p/2000635.html
Copyright © 2011-2022 走看看