`
chengyue2007
  • 浏览: 1469672 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

javascript 打印功能是我的最好的,搜集的,整理全的。

    博客分类:
  • java
阅读更多

打印完事儿后还需要将原来的样式设置回来。

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
   <style media="print"> 
.Noprint  {DISPLAY:  none;} 
</style>
<style media="print"> 
@media print {
.noneprint{display:none;}
}
.tabPrint td
{
border-left:#000000 solid 1px;
border-top:#000000 solid 1px;
height:21px;
}
table.tabPrint
{
border-right:#000000 solid 1px;
border-bottom:#000000 solid 1px;
}
.nextPage
{
page-break-after:always;
}
.linetd
{
border-bottom:solid 1px #000;
}
</style>
<style type="text/css">
.test{
background-color:#000000;
}
.test td{
 background-color:#FFFFFF;

}

</style>
<title>打印测试</title> 
<script language="javascript">
//直接打印
function print1(){

 WebBrowser.ExecWB(6, 2);

}
//预览
function print2(){
 
 setSytle();

 WebBrowser.ExecWB(7, 2);
 
}
//设置
function print3(){

WebBrowser.ExecWB(8, 1);

}
//关闭
function print4(){
WebBrowser.ExecWB(45, 1);

}

function setSytle(){
var t=document.getElementById("mytable");

t.border="0";
t.cellpadding="0";
t.cellspacing="0" ;

t.className="tabPrint";
document.title="";
 //这个函数是设置打印的时候不显示页眉和页脚的vbscript代码
 pagesetup_null();
}

 

</script>


<script language="VBScript">
dim hkey_root,hkey_path,hkey_key
hkey_root="HKEY_CURRENT_USER"
hkey_path="\Software\Microsoft\Internet Explorer\PageSetup"
//设置网页打印的页眉页脚为空
function pagesetup_null()
on error resume next
Set RegWsh = CreateObject("WScript.Shell")
hkey_key="\header"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""
hkey_key="\footer"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""


end function
//设置网页打印的页眉页脚为默认值
function pagesetup_default()
on error resume next
Set RegWsh = CreateObject("WScript.Shell")
hkey_key="\header"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P"
hkey_key="\footer"
RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&u&b&d"
end function
</script>
</head>  
<body>
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=WebBrowser width=0></OBJECT>
<center class="Noprint"> 
<input type="button" value="直接打" onClick="print1();"> 
<input type="button" value="预览" onClick=" print2()"> 
<input type="button" value="设置" onClick="print3();"> 
<input type="button" value="关闭" onClick="print4();"> 
 
</center> 
<br>
<!--<table id="mytable" width="555" height="142" border="0" align="center" cellpadding="0" cellspacing="0"  class='tabPrint'>-->
<!--<table id="mytable" width="555" height="142" border="0" align="center" cellpadding="0" cellspacing="0"  class='test'>-->
<!--开始的时候设置透过全前景看背景 的格式,但是当在真正的打印的时候用另外设置的一种格式来弄。
并且事实表明,javascript中可以调用vpscript代码
-->
<table id="mytable" width="555" height="142" border="0" align="center" cellpadding="0" cellspacing="1"  class='test'>

  <tr>
    <td width="109">你好你好</td>
    <td width="130">你好你好</td>
    <td width="110">你好你好</td>
    <td width="100">你好你好</td>
    <td width="68">你好你好</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>


</body> 
</html>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics