代码实现打印功能(asp.net+javascript) |
本文标签:asp.net,代码,打印 一.在服务器端实现 1.这个是在本页面上的.cs文件里写的 复制代码 代码如下: if (resultInt > 0) { //清除验证码 ,显示执行结果,并转向新的地址 Session["YanZhengMa"] = ""; String caoCode = "if(confirm(提交成功,是否打印))" + "{" + "window.location.href=printTKZ.aspx?type=BF&BMId=" + _flowidValue +"&bufeitime="+ _jfTimeValue +"&palJE=" +_shouXianValue + "&goTo=buFeiList.aspx;" + "}" + "else" + "{" + "window.location.href=buFeiList.aspx;" + "}"; MessageBox.alert(Page, (object)caoCode); } <body onload="vbscript:window.print()"> 就可以了 二.在客户端实现 复制代码 代码如下: <script language="javascript"> function doPrint() { bdhtml=window.document.body.innerHTML; sprnstr=" <!--startprint-->"; eprnstr=" <!--endprint-->"; prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); window.document.body.innerHTML=prnhtml; window.print(); } </script> <!--startprint--> 放在打印地方的开头 <!--endprint-->打印地方的结尾 <a href="javascript:;" onclick="doPrint()">打 印 </a> |