打印时不在弹出窗口中显示打印视图

时间:2017-01-11 09:01:50

标签: javascript jquery

当我调用PrintElem函数时,弹出窗口将在新窗口中打开(它显示打印视图)。我不想显示任何弹出窗口只是直接打印而没有任何视图。 尝试甚至隐藏流行音乐仍然会重定向/打开一个窗口。

button click__html+='<button type="button" class="btn btn-default" onclick = "PrintElem(\'.modal-body\');" >
<span class="glyphicon glyphicon-print"></span>&nbsp;&nbsp;Print</button>';

function PrintElem(elem){Popup($(elem).html());}

function PrintElemview(elem)
{
     Popup($(elem).html());
}

function Popup(data) 
{       
      var mywindow = window.open('', 'my div', 'height=auto,width=auto');
        mywindow.document.write('<html ><head><title></title>');
        mywindow.document.write('<link rel="stylesheet" href="assets/css/printpage.css">');         
        mywindow.document.write('</head><body style="width:320;height:450;border:1px solid black;marrgin-left: auto;padding:10px!important;">');                
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');
        mywindow.document.write("<style type='text/css' media = 'print'>@page {size:A5;}@page :left {  margin-left: 3cm;}@page :right { margin-left: 4cm;}</style>");
        mywindow.document.write("<style type='text/css'>.boreer{border-bottom-style: double!important;}</style>");  
        mywindow.document.write("<style type='text/css'>.printdespbill > td{border: 1px solid black; border-top: none!important;border-bottom: none;border-collapse: collapse;}</style>");              
        mywindow.document.write("<style type='text/css'>.table-bordered{ border: 1px solid black!important;}</style>"); 
        mywindow.document.write("<style type='text/css'>body{ width: 6.5inc!important;font: 10px/1 'Open Sans';align:center!important;}</style>");                          
        mywindow.document.write("<style type='text/css'>.company_header{border-bottom: 12px solid black;}.docname{margin-top: 16px!important;}</style>");
        mywindow.document.write("<style type='text/css'>.printabl{ margin-bottom: 12px!important;}</style>");
        mywindow.document.write("<style type='text/css'>.print_desp_bill > tr > td{padding: 1px !important;border-bottom:none!important;border-top: none;}</style>");
        mywindow.document.write("<style type='text/css'>.presc_dts > tr > td{padding: 3px !important;}</style>");
        mywindow.document.write("<style type='text/css'>.billhead{text-align:center;text-decoration: underline;}</style>");
        mywindow.document.write("<style type='text/css'>.theadfont10px{font: 10px/1 'Open Sans', sans-serif;!important;}</style>");
        mywindow.document.write("<style type='text/css'>.content{font: 10px/1 'Open Sans', sans-serif;!important;}</style>");
        mywindow.document.write("<style type='text/css'>tbody >tr > td { font: 10px/1 'Open Sans', sans-serif;!important;}</style>");
        mywindow.document.write("<style type='text/css'>thead >tr > td { font: 10px/1 'Open Sans', sans-serif;!important;}</style>");
        mywindow.document.write("<style type='text/css'>.presc_hd >tr > th { font: 10px/1 'Open Sans', sans-serif;!important;font-weight: bold;}</style>");
        mywindow.document.write("<style type='text/css'>.table-bordered > tbody >tr >td{ border: 1px solid black!important;}</style>");         
        mywindow.document.write("<style type='text/css'>.table-bordered > thead >tr >th{ border: 1px solid black!important;}</style>");
        mywindow.document.write("<style type='text/css'>.table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {border-top:none!important}</style>");           
         mywindow.document.close(); // necessary for IE >= 10
        mywindow.focus(); // necessary for IE >= 10
        mywindow.print();
        mywindow.close();           
        location.href=location.href;

        if($('#redirect').val() == '1')
        {
            var base_url = "<?php echo base_url();?>";
            // redirect.location()
             window.location=base_url+"patient_reg";
        }
        // @media print {
        //   body { font-size: 10pt }
        // }
    return true;
}

1 个答案:

答案 0 :(得分:1)

操作系统在静音打印方面存在一些安全限制,因为如果您访问具有您的代码类型的特定网站,它可以用于自动打印不需要的项目。

希望它有所帮助!!