Reputation: 728
When i call PrintElem function a popup opens in new window(it shows print view). I don't want to show that any popup just direct print without any view. Tried even hiding pop also still its redirecting /opening a window.
button click__html+='<button type="button" class="btn btn-default" onclick = "PrintElem(\'.modal-body\');" >
<span class="glyphicon glyphicon-print"></span> 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;
}
Upvotes: 1
Views: 446
Reputation: 242
There are some security restrictions from OS on silent printing since it can be used to print unwanted items automatically if you visit certain site which has your type of code.
Hope it helps!!
Upvotes: 1