2017-01-11 3 views
1

Beim Aufruf der PrintElem-Funktion öffnet sich ein Popup in einem neuen Fenster (es wird die Druckansicht angezeigt). Ich möchte nicht zeigen, dass Popup nur direkten Druck ohne irgendeine Ansicht. Versucht sogar Pop zu verstecken auch immer noch seine Umleitung/Öffnen eines Fensters.Drucken ohne Anzeige der Druckansicht im Popup

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; 
} 
+0

im Grunde wird es den Druckdialog öffnen, weil es nur in die Benutzeroberfläche des Browsers einhakt, nicht viel, was Sie dagegen tun können. Wenn Sie googlen, könnten Sie lesen, dass viele Leute versucht haben, es vorher zu lösen, und die Ergebnisse sind nicht sehr befriedigend - entweder IE-only-Lösungen oder Software von Drittanbietern oder Browser-Add-ons etc etc: https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#safe=active&q=javascript+print+ohne+dialog – ADyson

+0

@ADyson Danke für Ihre Zeit bin Druckerdialog nicht stören. Es zeigt ein Popup mit URL und meine Druckansichtsseite. –

+0

das ist weil du es sagst. Das macht dein ganzes Skript. Wenn Sie Medienabfragen in Ihrem CSS anstelle einer separaten Druckansichtsseite verwenden, können Sie window.print einfach direkt von der Originalseite aus aufrufen oder dem Benutzer erlauben, dies selbst zu tun, und die druckbare Version wird auf diese Weise erstellt. Hier ist ein Tutorial: http://www.joshuawinn.com/css-print-media-query/ – ADyson

Antwort

1

Es gibt einige Sicherheitseinschränkungen von OS auf leisen Druck, da sie verwendet werden können, unerwünschte Elemente automatisch zu drucken, wenn Sie bestimmte Website besuchen, die Ihre Art von Code.

Hoffe es hilft !!