我想从html(aspx)页面打印一个div。我从相关问题how to print part of rendered html page in javascript
的答案中获取了stackoverflow的帮助但是当我点击打印链接时,没有任何事情发生,有谁能告诉我这里做错了什么?我想做些什么才能让它变得可行?
我的aspx页面就像
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Report for Form Sale Money recipt</title>
<link href="../CSS/Report/myprintstyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
printDivCSS = new String ('<link href="../CSS/Report/myprintstyle.css" rel="stylesheet" type="text/css">')
function printDiv(ReportDiv) {
window.frames["print_frame"].document.body.innerHTML=printDivCSS + document.getElementById(divId).innerHTML
window.frames["print_frame"].window.focus()
window.frames["print_frame"].window.print()
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id ="ReportDiv">
<b>Report Div</b> <a href='javascript:printDiv('ReportDiv')'>Print</a><br/>
<label>Money Receipt Number</label> <asp:Label runat = "server" ID = "lblMRN"></asp:Label><br />
<label>Reference</label> <asp:Label runat = "server" ID = "lblReference"></asp:Label><br />
<label>Form Serial</label> <asp:Label runat = "server" ID = "lblFormSL"></asp:Label><br />
<label>Name</label> <asp:Label runat = "server" ID = "lblName"></asp:Label><br />
<label>Program</label> <asp:Label runat = "server" ID = "lblProgram"></asp:Label><br />
<label>Semester</label> <asp:Label runat = "server" ID = "lblSemester"></asp:Label><br />
<label>Paid Amount</label> <asp:Label runat = "server" ID = "lblPaidAmount"></asp:Label><br />
<label>Comments</label> <asp:Label runat = "server" ID = "lblComments"></asp:Label><br />
<label>Bank</label> <asp:Label runat = "server" ID = "lblBank"></asp:Label>
</div>
<iframe name='print_frame' width='0' height='0' frameborder='0' src='about:blank'></iframe>
</form>
</body>
</html>
当我点击打印时,我在浏览器底部发现页面错误。
答案 0 :(得分:0)
试试这个:
window.frames["print_frame"].focus();
window.frames["print_frame"].print();