admin管理员组文章数量:1307658
I have a javascript print function:
function printDetails() {
var printContent = document.getElementById('<%= divMail.ClientID %>');
var windowUrl = 'about:blank';
var uniqueName = new Date();
var windowName = 'Print' + uniqueName.getTime();
var printWindow = window.open(windowUrl, windowName, 'left=500,top=500,width=0,height=0');
printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
return false;
}
I have the following HTML:
<div id="divMail" runat="server" >
<div id="showTopDetailsContent" style="display: none; position:relative;">
MORE HTML
</div>
</div>
And the following JQuery/Script:
$('#showTopDetailsContent').toggle(300);
The problem: When I Print I get the Contents of the divMail (DIV) and send them to the Print Function, the problem is that since I have a DIV inside divMail that is Hidden it will not be displayed in the Print. How do I make the Print Function Display that hidden DIV?
I have a javascript print function:
function printDetails() {
var printContent = document.getElementById('<%= divMail.ClientID %>');
var windowUrl = 'about:blank';
var uniqueName = new Date();
var windowName = 'Print' + uniqueName.getTime();
var printWindow = window.open(windowUrl, windowName, 'left=500,top=500,width=0,height=0');
printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
return false;
}
I have the following HTML:
<div id="divMail" runat="server" >
<div id="showTopDetailsContent" style="display: none; position:relative;">
MORE HTML
</div>
</div>
And the following JQuery/Script:
$('#showTopDetailsContent').toggle(300);
The problem: When I Print I get the Contents of the divMail (DIV) and send them to the Print Function, the problem is that since I have a DIV inside divMail that is Hidden it will not be displayed in the Print. How do I make the Print Function Display that hidden DIV?
Share Improve this question asked Apr 22, 2013 at 19:00 Eric BergmanEric Bergman 1,44312 gold badges47 silver badges86 bronze badges3 Answers
Reset to default 4try this:
printWindow.document.getElementById('showTopDetailsContent').style.display='block';
after the
printWindow.document.write(printContent.innerHTML);
You can specify it as visible for printing in CSS:
@media screen {
#showTopDetailsContent { display: none; }
#showTopDetailsContent.show { display: block; }
}
@media print {
#showTopDetailsContent { display: block !important; }
}
And instead of using .toggle()
which applies inline styles, use a class.
$('#showTopDetailsContent').toggleClass('show');
you need to suppress the border in CSS
/* stop page from printing footer */
@page {
size: auto; /* auto is the initial value */
margin: 0mm; /* this affects the margin in the printer settings */
}
but that will put your content close to the edge so I'd wrap everything in a DIV with some padding
本文标签: jqueryHow to print a Hidden DIV when printing using a JavaScript FunctionStack Overflow
版权声明:本文标题:jquery - How to print a Hidden DIV when printing using a JavaScript Function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741845031a2400732.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论