JS打印html頁面


JS部分的代碼

    <object id="WebBrowser" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>
    <!-- <script type="text/javascript" src="/JScript/PrintView/InvoicePrint.js"></script>-->
    <script type="text/javascript">
        function printNew() {
            bdhtml = window.document.body.innerHTML;
            sprnstr = "<!--startprint-->"; //開始打印標識字符串有17個字符
            eprnstr = "<!--endprint-->"; //結束打印標識字符串
            prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17); //從開始打印標識之后的內容
            prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr)); //截取開始標識和結束標識之間的內容
            var splitFirst = prnhtml.split("background='/Images/printTax.gif'"); //去掉打印中的背景圖片
            var ResultString = splitFirst.join(''); //組合被分割的頁面
            var PrintWin = window.open('about:blank', 'Print', 'height=1px,width=1px,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no,top=20px,left=20px');
            PrintWin.document.write(ResultString);
            //PrintWin.document.all.WebBrowser.ExecWB(7, 1);//打印預覽
            PrintWin.document.all.WebBrowser.ExecWB(6, 6); //打印document.all.WebBrowser.ExecWB(45,1)
            PrintWin.document.all.WebBrowser.ExecWB(45, 1);
            alert("090o9oi");
            // PrintWin.setTimeout("window.close()", 100);
            PageSetup_Default(); //設置為原始值
        }
        function thisChose() {
            window.parent.CloseDiv();
        }
    </script>

  html部分代碼

<html>
<head>
    <title></title>
</head>
<body>
      <!--startprint-->
            <%=pointlist%><!--需要打印的代碼-->
      <!--endprint-->
</body>
</html>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM