【问题标题】:Need to Hide or clode the window while printing the current page in php Codeigniter在php Codeigniter中打印当前页面时需要隐藏或关闭窗口
【发布时间】:2017-07-02 10:14:08
【问题描述】:

在这里,我有一个预订表格,其中包含多个带有打印按钮的输入字段。在填写预订表格时,所有字段都存储到数据库中。(这里使用 ajax 将数据存储到 db)。在 ajax 中通过获取成功消息,需要获取最后插入 id 以检索来自 mysql 的最后插入记录db.After 那之后,我将该 id 传递给控制器​​到视图。在该视图页面中,正在正文加载函数中调用 printcontent。每件事都运行良好。但需要隐藏打开的窗口。需要在不打开窗口的情况下获取打印预订票。我在下面附上了我的 jquery 代码,检查我的代码并让我知道。 我的jQuery代码:

        <script>

            $( document ).ready(function() {
             printcontent($(".dvData").html());
             //$(".dvData").hide();
            });


            function printcontent(content)
            {
                var mywindow;
                var mywindow = window.open('', 'mywindow', 'width:210mm; height:148mm;');
                //$('.dvData').css('visibility', 'hidden'); 
                mywindow.document.write('<html><body>');
                mywindow.document.write(content);
                mywindow.document.write('</body></html>'); 

                mywindow.document.close(); 

                mywindow.print();
                alert("Trip Sheet Printed Successfully");
                //mywindow.style.visibility = 'hidden';

                return true;
            }
            </script>

谢谢@

【问题讨论】:

    标签: php jquery mysql codeigniter


    【解决方案1】:

    试试这个

     function PrintPanel() {
           var panel = document.getElementById("<%=Panel1.ClientID%>");
           var printWindow = window.open('', '', 'height=120,width=300');
           printWindow.document.write('<html><head><title>YOUR TITLE</title>');
           printWindow.document.write('</head><body >');
           printWindow.document.write(panel.innerHTML);
           printWindow.document.write('</body></html>');
           printWindow.document.close();
           setTimeout(function () {
               printWindow.focus();
               printWindow.print();
               printWindow.close();
           }, 500);
        return false;
     }
    

    或将您的函数设置为代码末尾的return false;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 2017-10-30
      • 1970-01-01
      相关资源
      最近更新 更多