我有一个网页,它利用bPopUp用 jQuery 弹出一个模态窗口。
该窗口的内容正是我想要打印的内容(主页上没有其他内容)。
我试过在弹出窗口上链接一个按钮来运行命令,window.print();但这只是打印整个页面,显示弹出窗口遮挡了页面的其余部分。
有谁知道我如何只能打印弹出窗口的内容而没有其他内容?
谢谢
小智 7
示例 HTMP
<div id='DivIdToPrint'>
<p>This is a Popup which needs to be printed.</p>
</div>
<div>
<p>Do not print.</p>
</div>
<input type='button' id='btn' value='Print' onclick='printDiv();'>
Run Code Online (Sandbox Code Playgroud)
Javascript
function printDiv()
{
var divToPrint=document.getElementById('DivIdToPrint');
var newWin=window.open('','Print-Window');
newWin.document.open();
newWin.document.write('<html><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');
newWin.document.close();
setTimeout(function(){newWin.close();},10);
}
Run Code Online (Sandbox Code Playgroud)
为您的 Popup div 提供一个 ID 并使用上面的示例。您需要提供内联样式以准确打印弹出窗口。
| 归档时间: |
|
| 查看次数: |
9106 次 |
| 最近记录: |