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

ASP
asp+的页面指示标识
asp+文件上传增强实例
让ASP也可以连接MYSQL
ASP文件操作--列出目录及文件
将站点加入频道栏源代码
如何在页面上动态的生成 WebForm控件
避免表单的重复提交又一方法(js)
灵活实用的页面广告实例
如何用javascript识别Netscape 6 浏览器
使用javascript实现邮箱快速登录的方法!!
如何从数据库得到一个列表表单
使用Cookie来跟踪用户
用DHTML来模拟实现下拉菜单
javascript做的数据校验(校验IP地址等)
通过网络域名得到这台主机的IP地址
如何在ASP中使用类
SQL Server中单引号的两种处理技巧
Display data From database into 2 Column
存储过程对页面访问速度的影响
在ASP中使用类

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 164 ::
收藏到网摘: 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()>