[英]Page reload after print contents
I am using div to print (window.print()) for printing contents. 我正在使用div打印(window.print())来打印内容。 But after print function the side menu of the current page is not working (not supporting).
但是在执行打印功能后,当前页面的侧面菜单不起作用(不支持)。 Because of this issue I am using location.reload();
由于这个问题,我正在使用location.reload();。 for page reload.
用于页面重新加载。 but that also not working.
但这也不起作用。 Please help me.
请帮我。
My div to print function is, 我的div打印功能是
function printDiv(divName) {
$("#DataTables_Table_0_length").hide();
$("#DataTables_Table_0_filter").hide();
$("#DataTables_Table_0_info").hide();
$("#DataTables_Table_0_paginate").hide();
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
$("#DataTables_Table_0_length").show();
$("#DataTables_Table_0_filter").show();
$("#DataTables_Table_0_info").show();
$("#DataTables_Table_0_paginate").show();
window.location.reload(true);
}
You can wrap your print logic inside if block and use another window for your printing content: 您可以将打印逻辑包装在if块中,并使用另一个窗口作为打印内容:
if(window.print){
var printWindow = window.open('', 'Printing...', 'height=400,width=600');
printWindow.document.write(YOUR_CONTENT_OF_DIV);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
} else {
alert("Printing is not supported by browser")
}
If you're using some theme, probably the side menu is being hide using the CSS media query "@media print". 如果您使用的是主题,则可能是使用CSS媒体查询“ @media print”隐藏了侧面菜单。 Just use the debugger or even your IDE to find the occurrences.
只需使用调试器,甚至是您的IDE来查找事件。 Btw, you should also create a CSS rule for print your div instead of using JS, by simply:
顺便说一句,您还应该创建CSS规则来打印div而不是使用JS,方法是:
@media print {
.your-div #DataTables_Table_0_length {
display: none;
}
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.