发新话题
打印

ASP 实现预览打印的问题

ASP 实现预览打印的问题

我做了一个显示数据库中记录的页面,不过我用了框架,用IE的打印功能会打印整个页面,如果我想打印显示纪录的页面,而不是整个框架页面,怎么实现?在hotmail的信箱中有一个打印邮件的功能,我觉得和我的目的是一样的,请各位高手指点迷津

TOP

在<head></head>之间加入如下代码;  
<OBJECT  Classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2  height=0  id=WB  width=0></OBJECT>  
<script  language=javascript>  
function  doPrintSetup(){  
WB.ExecWB(8,1)  
}  
function  doPrintPreview(){  
WB.ExecWB(7,1)  
}  
</script>  

在<body>中调用:  
<input  type=button  name=button1  value="打印设置"  onclick="return  doPrintSetup()">  
<input  type=button  name=button2  value="打印预览"  onclick="return  doPrintPreview()">  
<input  type=button  name=button3  value="打印本页"  onclick="javascript:print()">

TOP

function  printPreview()  
{  
   try  
   {  
       var  printWindow  =  window.open("","_blank");  
       var  str  =  "<OBJECT  id=WebBrowser  classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2  height=0  width=0></OBJECT>"  
       var  s  =  "<html>\r\n";  
       s  +=  "<head>";  
       s  +=  "<LINK  href='../../pic/broker30.css'  type='text/css'  rel='stylesheet'>";  
       s  +=  "<meta  http-equiv='Content-Type'  content='text/html;  charset=gb2312'>";  
       s  +=  "</head>";  
       s  +=  "<body><center><br>";  
       s  +=  "<div  align=center  style='width:96%'>";  
       s  +=  document.body.innerHTML;  
       s  +=  "</div>";  
       s  +=  "</center></body>";  
       s  +=  "</html>";  
       printWindow.document.write(s);  
       printWindow.document.close();  
       printWindow.document.body.insertAdjacentHTML("beforeEnd",  str);  
       printWindow.document.all.WebBrowser.ExecWB(7,1);  
       printWindow.close();  
   }  
   catch(e)  
   {  
       alert("您的浏览器版本太低,请升级您的浏览器!");  
   }  
}

TOP

发新话题