0
我想在html报告页面中执行打印操作。我只需要点击“导出PDF”按钮中的PDF页面的某些部分。 因此,我将所需内容放置到一个新的iframe中,并在单击按钮时打印iframe。其工作完美。打印iframe内容jquery不能在远程服务器上工作
这里是我的代码
$('#btnprint').on('click',function(){
$('#print-iframe').contents().find('html').html($('#divprintheader').html() + $('#divreport').html());
$("#print-iframe").get(0).contentWindow.print();
});
<table id="tblentrancereport" class="reporttable" style="width: 100%">
<thead>
<tr>
<th>Name</th>
<th>Count</th>
<th>Amount</th>
</tr>
</thead>
<tbody></tbody>
</table>
<div id="divprintheader" style="display: none">
From : <span id="spnfromdate"></span> To : <span id="spntodate"></span>
<div id="divprintfilter">
Filtered By : <span id="spnfilteredby"></span>
<div id="divcontentbelongto">
</div>
</div>
</div>
<button id="btnprint">Export PDF</button>
<iframe name="print_frame" id="print-iframe" width="0" height="0" frameborder="0" src="about:blank"></iframe>
不幸的是,当我的代码移动到我的生产服务器(Windows Server 2012),我不是在iframe中获取内容(打印窗口是未来)。尽管iframe中填充了新的动态构成内容(我可以在检查页面元素时看到),但它并未显示在打印内容中。任何人都可以弄清楚我错误的地方。
下面是截图
当我在我的本地
打印试过当我在我的服务器尝试打印
UPDATE 而奇怪的是,当我检查元素并扩展开发人员工具中的内容,然后单击“导出PDF”按钮,其工作..:O
不能描绘出错误:(
也许试着用'sandbox =“allow-forms allow-modals allow-popups allow-same-origin allow-scripts来移除'src'属性'' –
@MichaelSchwartz谢谢你的回复!但不工作.. :( – NCA
而奇怪的是,当我检查元素和展开内容的开发工具,然后点击“导出PDF”按钮,其工作。 无法找出错误:( – NCA