当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp.net结合js的网页打印程序

ASP
ASP调用ORACLE存储过程并返回结果集
用ASP实现网页BBS
关于Global.asa文件的深入研究与session变量失效提示的具体方法
简易ASP+注册系统
防护手册:如何防止ASP木马在服务器上运行
用Visual Basic实现多画面播放功能之二
如何增强ASP程序性能(1)
如何增强ASP程序性能(2)
如何增强ASP程序性能(3)
ASP备份数据库
二十八条改善 ASP 性能和外观的技巧
在Form域中Post大于100K的数据
如何使用ASP制作模似动态生长的表单?
Microsoft IIS 真的如此「不安全」吗?(1)
Microsoft IIS 真的如此「不安全」吗?(2)
Microsoft IIS 真的如此「不安全」吗?(3)
Microsoft IIS 真的如此「不安全」吗?(4)
Microsoft IIS 真的如此「不安全」吗?(5)
关于页面和代码分离
ServerVariables 对路径的操作

ASP 中的 asp.net结合js的网页打印程序


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 221 ::
收藏到网摘: n/a

循环打印div中的内容:

以下为引用的内容:

  <input type="button" onClick="javascript:printpage(’’myDiv’’);" value="打印"> 
流程: 
从数据库中取出记录-》放入aspx页面的一个Div中打印 
例子: 
在aspx中定义一个DIV,如: 
<div id="myDiv">   
     <table border="0"  width="100%"> 
         <tr> 
         <td> 
        <table align="center" border="0" cellpadding="5" cellspacing="1" 
            width="100%" class="test"> 
          <tr bgcolor="#CDD9F1" align="center"> 
            <td height="22" colspan="2" valign="middle">凭证</td> 
          </tr> 
        </table> 
         </td> 
    </tr> 
    </table> 
</div> 
在apsx中定义一个按钮,按下事件触发 
printpage(’’myDiv); 
Printpage方法如下(javascript): 
function printpage(myDiv){ 
   var newstr = document.all.item(myDiv).innerHTML; 
   var oldstr = document.body.innerHTML; 
   document.body.innerHTML = newstr; 
   window.print(); 
   document.body.innerHTML = oldstr; 
   return false; 
}  

===================================================
 
<script  language="JavaScript">  
var HKEY_Root,HKEY_Path,HKEY_Key; 
HKEY_Root="HKEY_CURRENT_USER"; 
HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; 
//设置网页打印的页眉页脚为空 
function PageSetup_Null() 

 try 
 { 
         var Wsh=new ActiveXObject("WScript.Shell"); 
  HKEY_Key="header"; 
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,""); 
  HKEY_Key="footer"; 
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,""); 
 } 
 catch(e){} 


//设置网页打印的页眉页脚为默认值 
function  PageSetup_Default() 
{  
 try 
 { 
  var Wsh=new ActiveXObject("WScript.Shell"); 
  HKEY_Key="header"; 
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P"); 
  HKEY_Key="footer"; 
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d"); 
 } 
 catch(e){} 

</script> 
<input type="button" value="清空页码" onclick=PageSetup_Null()> 
<input type="button" value="恢复页码" onclick=PageSetup_Default()>