我发现了一个问题,我的打印DIV语法打印特定格给出了打印预览空白页
HTML
<button class="btn btn-primary dropdown-toggle" type="button" id="cetak_temuan" data-toggle="dropdown"><i style="color:white" class="fa fa-print"></i> Cetak</button>
<div class="mod">
<table width="100%" style="margin-bottom: 20px">
<tr>
<td colspan="5" ><h3 align="center">INSPEKTORAT PROVINSI MALUKU</h3>
</td>
</tr>
<tr>
<td width="15%">Nama SKPD</td>
<td width="2%" align="center">:</td>
<td width="50%" id="skpd_table"></td>
</tr>
<tr>
<td>Judul Laporan</td>
<td align="center">:</td>
<td id="jlaporan_table"></td>
<td width="20%">Periode Laporan</td>
<td width="2%" align="center">:</td>
<td width="40%" id="prlp_table"></td>
</tr>
<tr>
<td>Nomor Laporan</td>
<td align="center">:</td>
<td id="nolaporan_table"></td>
<td width="20%">Periode Tindak Lanjut</td>
<td width="2%" align="center">:</td>
<td width="40%" id="prtl_table"></td>
</tr>
<tr>
<td colspan="5"><h4 align="center">URAIAN TEMUAN TINDAK LANJUT</h4></td>
</tr>
</table>
<table class="table table-borderless table-striped" >
<thead>
<tr>
<th colspan="2">Kondisi</th>
<th colspan="2">Penyebab</th>
<th colspan="2">Rekomendasi</th>
<th colspan="2">Tindak lanjut</th>
</tr>
</thead>
<tbody id="kondisi_tabel">
</tbody>
</table>
</div>
JS
$('#cetak_temuan').on('click', function() {
var dfd = $.Deferred();
// Add handlers to be called when dfd is resolved
dfd.done(PrintElem2('.mod'));dfd;
});
function PrintElem2(elem){
Popup2($(elem).html());
}
function Popup2(data)
{
var mywindow = window.open('','Print A Page ','height=400,width=600');
mywindow.document.write('<style type="text/css" media="print">@page{size:landscape;}</style><html><head><title>Cetak Lapora</title>');
mywindow.document.write(' <link rel="stylesheet" href="<?php echo base_url();?>bootstrap/css/bootstrap.css">');
mywindow.document.write('</head><style type="text/css" > table tr td {font-size:12px;}table > thead > tr >th , table> tbody > tr > td {font-size:10px} #dontprint{display:none} .dontshow{display:display} </style><body>');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
//mywindow.print();
mywindow.document.close();
myDelay = setInterval(checkReadyState2,10);
function checkReadyState2(){
if(mywindow.document.readyState == "complete") {
clearInterval(myDelay);
mywindow.focus();
mywindow.print();
mywindow.close();
}
}
return true;
}
每当我试着我的代码,它只是给我一个打印预览的空白页面。我尝试使用chrome
。我尝试了另一种网络浏览器,如Opera
,它的工作方式与我的预期一样,但是当我关闭已弹出的打印预览窗口时,该页面无法单击或键入单词。我的语法有什么问题?
或者有人可能会建议我使用javascript打印特定div的另一种方式?
但为什么当我在Opera上试用这个时,它只是工作? – Gagantous
您使用的是哪个版本的chrome?可能是'base_url()'的兼容性。这就是为什么我建议如果你的代码没有与'bootstrap'有关的句子,那么你需要检查那行代码。 – MKR
版本61.0.3163.100(官方版本)(64位) – Gagantous