专注网站建设八年 品牌的力量 值得信赖
网站首页 公司简介 域名注册 企业邮局 网站模板 网页特效 源码下载 网站知识 客户服务 联系我们
      现在的位置:首页  |  

web打印,实现隐藏不想打印的页面元素,以及页眉和页脚

<html>
<head>
    <title>web打印去掉页眉页脚,以及不想打印出的页面元素</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css" media="print">
        .Noprint{display:none;}
        .PageNext{page-break-after:always;}
    </style> 
    <script language="javascript">
        function printpr() //预览函数
        {
            document.all("qingkongyema").click();//打印之前去掉页眉,页脚
            //document.all("dayinDiv").style.display="none"; //打印之前先隐藏不想打印输出的元素(此例中隐藏“打印”和“打印预览”两个按钮)
            var OLECMDID = 7;
            var PROMPT = 1;
            var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
            document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
            WebBrowser1.ExecWB(OLECMDID, PROMPT);
            WebBrowser1.outerHTML = "";
            //document.all("dayinDiv").style.display="";//打印之后将该元素显示出来(显示出“打印”和“打印预览”两个按钮,方便别人下次打印)
        }

        function printTure() //打印函数
        {
            document.all('qingkongyema').click();//同上
            document.all("dayinDiv").style.display="none";//同上
            window.print();
            document.all("dayinDiv").style.display="";
        }
        function doPage()
        {
            layLoading.style.display = "none";//同上
        }
    </script>

    <script language="vbscript" type="text/vbscript">
        dim hkey_root,hkey_path,hkey_key
        hkey_root="HKEY_CURRENT_USER"
        hkey_path="\Software\Microsoft\Internet EXPlorer\PageSetup"
        '//设置网页打印的页眉页脚为空
        function pagesetup_null()

        on error resume next
        Set RegWsh = CreateObject("WScript.Shell")
        hkey_key="\header"
        RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""
        hkey_key="\footer"
        RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""
        end function

        '//设置网页打印的页眉页脚为默认值
        function pagesetup_default()
        on error resume next
        Set RegWsh = CreateObject("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"
        end function
    </script>

</head>
<body background="images/background_01.gif" leftmargin="0" topmargin="0" rightmargin="0"
    bottommargin="0" style="background-position: center 50%">
    <div align="center">
        你希望打印的内容..........
    </div>
    <div align="center" id="dayinDiv" name="dayinDiv" class="Noprint">
        <input type="button" class="tab" value="打印" onclick="printTure();">&nbsp;&nbsp;
        <input type="button" class="tab" value="打印预览" onclick="printpr();">
        <input type="hidden" name="qingkongyema" id="qingkongyema" class="tab" value="清空页码"
            onclick="pagesetup_null()">&nbsp;&nbsp;
        <input type="hidden" class="tab" value="恢复页码" onclick="pagesetup_default()">
    </div>
</body>
</html>

返回上页
  QQ:94794733   Email:500600949@sohu.com  冀ICP备13004392号-1  您是进入本站的第【0】位浏览者