zoukankan      html  css  js  c++  java
  • IE的打印window.print

    window.print是IE打印中的一种比较简单的打印方法。

    默认window.print打印会将页眉页脚也打印出来,可以通过javascript控制去掉页眉页脚。

    function doPrint() {

    /// 隐藏不需要打印的内容
            try
        {
            PageSetup_Null();
        }
        catch(e)
        {
            var errorMsg = e.message+"\r"+"请设置:IE选项->安全->Internet->"+"ActiveX控件和插件"+"\r"+"对未标记为可安全执行脚本的ActiveX的控件初始化并执行脚本->允许/提示";
            alert(errorMsg);
            return;
        }
        window.print();
    }

        </script>

        <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()
    {
          var Wsh=new ActiveXObject("WScript.Shell");
          HKEY_Key="header";
          Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
          HKEY_Key="footer";
          Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
          HKEY_Key="margin_left"
          Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0"); //键值设定--左边边界

          HKEY_Key="margin_top"
          Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0"); //键值设定--上边边界

          HKEY_Key="margin_right"
          Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0"); //键值设定--右边边界

          HKEY_Key="margin_bottom"
          Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0"); //键值设定--下边边界
    }

    ===================================================================

    调用window.print()时,可以利用css来控制页面中的东西是否显示
    <style>
    @media print
    {
      .noprint{
      display
    :none
      
    }
    }
    </style>
    HTML如下:
    <table width="757" height="174" border="0" align="center"cellpadding="0"
    cellspacing
    ="0">
    <tr class="noprint">
    <td height="133" align="center" valign="top">
    <img src="Images/top.jpg" width="757" height="133"></td>
    </tr>
    </table>
    此时<tr class="noprint">是不打印的tr


    下面是media的相关
    media类型是CSS属性媒体类型,用于直接引入媒体的属性。其语法格式如下:
    @media screen | print | projection | braille | aural | tv | handheld | all
    参数说明
    screen:指计算机屏幕。
    print:指用于打印机的不透明介质。
    projection:指用于显示的项目。
    braille:盲文系统,指有触觉效果的印刷品。
    aural:指语音电子合成器。
    tv:电视类型的媒体。
    handheld:指手持式显示设备。
    all:用于所有媒体。

     
     
    ==============================================================
    用window.print()打印网页如何去掉页眉页脚
    <script language="JavaScript">
    function PageSetup()
    {
    try
    {
    var HKEY_Root,HKEY_Path,HKEY_Key;
    HKEY_Root="HKEY_CURRENT_USER";
    HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
    var Wsh=new ActiveXObject("WScript.Shell");
    HKEY_Key="header";
    Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
    HKEY_Key="footer";
    Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
    HKEY_Key="margin_bottom"
    Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0.39370");
    HKEY_Key="margin_left"
    Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0.59055");
    HKEY_Key="margin_right"
    Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0.59055");
    HKEY_Key="margin_top"
    Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0.86614");
    alert ("您已成功完成打印边距设置!")
    }
    catch(e){alert ("页面设置失败,请手动设置!")}
    }
    </script>
  • 相关阅读:
    vim 常用命令
    centos 安装mysql
    centos部署ftp
    centos 6.8部署nginx
    ndk学习16: unix domain socket
    ndk学习14: 进程
    ndk学习13: proc
    ndk学习11: linux内存管理
    ndk学习10: linux文件系统
    ndk学习9: 动态使用共享库
  • 原文地址:https://www.cnblogs.com/linyechengwei/p/1717432.html
Copyright © 2011-2022 走看看