我开发了一个 MVC 4 应用程序。 有一个页面应该按原样打印。 如果我们必须选择打印机的打印弹出窗口关闭,网页会出现 404 错误。但是当页面刷新时,页面加载没有任何问题。
这可能是什么原因?提前致谢。
这是页面的一部分(整页很长)
@{
ViewBag.Title = "Details";
}
<div>
@{
string d = ViewBag.trans[0].REC_NO;
}
</div>
<form method="post" name="main" id="main">
<table x:str border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; width: 689px" id="table5" bgcolor="#F3F3F3">
<colgroup>
<col width="64" span="7" style="width:48pt">
</colgroup>
@if (ViewBag.status.ToString().Trim() == "1" && !String.IsNullOrEmpty(ViewBag.lastDate) )
{
<tr>
<td align="center" height="17" style="height: 12.75pt; color: windowtext; font-size: 10.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Arial; text-align: general; vertical-align: bottom; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px" width="676" colspan="7" align="left">
<p>
<font size="2" color="#FF0000" face="Trebuchet MS">Rejected
Receipt</font></td>
</tr>
}
@if (ViewBag.status.ToString().Trim() == "1" && String.IsNullOrEmpty(ViewBag.lastDate))
{
<tr>
<td height="17" style="height: 12.75pt; color: windowtext; font-size: 10.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Arial; text-align: general; vertical-align: bottom; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px" width="676" colspan="7" align="left">
<p align="center">
<font size="2" color="#FF0000" face="Trebuchet MS">Deleted
Receipt</font></td>
</tr>
}
@if (ViewBag.status.ToString().Trim() == "0" && !String.IsNullOrEmpty(ViewBag.lastDate))
{
<tr>
<td height="17" style="height: 12.75pt; color: windowtext; font-size: 10.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Arial; text-align: general; vertical-align: bottom; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px" width="676" colspan="7" align="left">
<p align="center">
<font size="2" color="#FF0000" face="Trebuchet MS">Initial
Receipt</font></td>
</tr>
}
@if (ViewBag.status.ToString().Trim() == "0" && String.IsNullOrEmpty(ViewBag.lastDate))
{
<tr>
<td height="17" style="height: 12.75pt; color: windowtext; font-size: 10.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Arial; text-align: general; vertical-align: bottom; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px" width="676" colspan="7" align="left">
<p align="center">
<font size="2" color="#FF0000" face="Trebuchet MS">Cashed
Receipt (Completed)</font></td>
</tr>
}
<tr>
<td height="17" style="height: 12.75pt; color: windowtext; font-size: 10.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Arial; text-align: general; vertical-align: bottom; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px" width="676" colspan="7" align="left">
<input type="submit" value="Print" name="B1" style="NonPrintable; color:#0000FF; font-size:8pt; font-family:Trebuchet MS" onClick="PrintElem('main')" class="NonPrintable">
</td>
</tr></table>
我用来打印区域的javascript函数。
<script type="text/javascript">
function PrintElem(elem)
{
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head><title>' + document.title + '</title>');
mywindow.document.write('</head><body >');
mywindow.document.write('<h1>' + document.title + '</h1>');
mywindow.document.write(document.getElementById(elem).innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
return true;
}</script>
最佳答案
这样使用
<a href="javascript:void(0);" onClick="window.print()">Print</a>
Web 浏览器允许您通过在浏览器的 URL 文本字段中输入 JavaScript 代码来直接执行 JavaScript 语句。您需要做的就是在您的代码之前放置一个 JavaScript:
以通知浏览器您希望运行 JavaScript。
关于javascript - "The resource cannot be found"打印页面时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41542065/