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

ASP
TSYS 新闻列表JS调用下载
使用asp代码突破图片的防盗连
一种理论上最快的Web数据库分页方法
asp:debug类调试程序
如何增加Referer功能--反向链接插件
pjblog中清空引用的小程序
光碟工具 Alcohol 120% v1.9.6.4719 下载(附序列号注册码)
ASP实现头像图像随机变换
UTF-8 Unicode Ansi 汉字GB2321几种编码转换程序
[转]XMLHTTPRequest的属性和方法简介
ASP常用函数:getpy()
我用ASP写的m行n列的函数,动态输出创建TABLE行列
ASP常用函数:Delay()
ASP常用函数:Trace()
[转]ASP实现关键词获取(各搜索引擎,GB2312及UTF-8)
对象标记具有无效的 ''MSWC.MyInfo'' ProgID
ServerVariables集合检索预定的环境变量
HTTP_HOST 和 SERVER_NAME 的区别详解
[转]ASP常用函数:TimeZone
Eval 函数 | Execute 语句 | ExecuteGlobal 语句

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


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