zoukankan      html  css  js  c++  java
  • asp.net局部页面打印,以及如何去掉打印时自动保留的URL地址(页眉页脚)

    最近做了asp.net的局部打印,开始是想用报表的,可总是感觉不如自定义页面灵活。

    那么就来说说asp.net页面局部打印是如何实现的。

      <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() { var hkey_root, hkey_path, hkey_key; hkey_root = "HKEY_CURRENT_USER" hkey_path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; 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 doPrint() { pagesetup_null(); bdhtml = window.document.body.innerHTML; sprnstr = "<!--startprint-->"; eprnstr = "<!--endprint-->"; prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17); prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr)); window.document.body.innerHTML = prnhtml; window.print(); } </script>
    //记得加这句代码 <OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0> </OBJECT>

    最后,在需要打印的页面部分用红色字体来标注即可,就可以实现页面局部打印以及去掉IE的页眉页脚设置 

    <!--startprint-->
    <div>
    <%=content%>
    </div>
    <!--endprint-->

     

  • 相关阅读:
    计算函数执行时间
    Go语言生成随机数
    413 Request Entity Too Large
    JavaScript变量与数据类型详解
    OAuth2.0认证详解
    prompt的工作原理
    JS 实现上传图片
    移动端的长按事件的实现
    实现自动关闭当前页面的效果
    前端异常捕获与上报
  • 原文地址:https://www.cnblogs.com/sulei4471/p/2814576.html
Copyright © 2011-2022 走看看