2017-01-11 12 views
1

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

基本的にはブラウザのUIにフックするだけなので、印刷ダイアログが開きます。多くはできません。もしあなたがこれを見つけたのであれば、多くの人が以前にそれを解決しようとしていて、結果はあまり満足できるものではないということを読んでみることができます.IE専用ソリューション、サードパーティ製ソフトウェア、またはブラウザアドオンetcなど:https://www.google.co.jp/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#safe=active&q=javascript+print+without+dialog – ADyson

+0

@ADysonありがとうございますプリンタのダイアログを気にする必要はありません。それはURLと私の印刷ビューページのポップアップを表示します。 –

+0

あなたがそれを伝えているからです。それがあなたのスクリプト全体です。別の印刷ビューページの代わりにCSSでメディアクエリを使用する場合は、元のページから直接window.printを呼び出すか、ユーザーがそれを自分で実行できるようにするだけで印刷可能なバージョンを取得できます。チュートリアルです:http://www.joshuawinn.com/css-print-media-query/ – ADyson

答えて

1

あなたがコードのあなたのタイプを持っている特定のサイトを訪問した場合、自動的に不要なアイテムを印刷するために使用することができますので、サイレント印刷上のOSからいくつかのセキュリティ上の制限があります。

希望すると助かります!

関連する問題