JavaScript打印

it2022-05-05  90

<HTML><HEAD><TITLE>JavaScript利用IE内置打印控件IEWebBrowser进行打印/打印页面设置/打印预览/控制分页打印</TITLE><META http-equiv=Content-Type content="text/html; charset=gbk" /><SCRIPT type="text/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 RegWsh = new ActiveXObject("WScript.Shell");hkey_key="\header";RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");hkey_key="\footer";RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");}catch(e){}}//设置网页打印的页眉页脚为默认值function pagesetup_default(){try{var RegWsh = new ActiveXObject("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");}catch(e){}}function printsetup(){   wb.execwb(8,1); // 打印页面设置} function printpreview(){   wb.execwb(7,1);// 打印页面预览} function printit() {  if (confirm('确定打印吗?')) {   wb.execwb(6,1); } } </SCRIPT><!--media=print 这个属性说明可以在打印时有效--><!--希望打印时不显示的内容设置class="Noprint"样式--><!--希望人为设置分页的位置设置class="PageNext"样式--><style media="print"><!--.Noprint{display:none;}.PageNext{page-break-after:always;}--></style><style type="text/css"><!--.STYLE1 {font-size: 12px}--></style></HEAD><BODY><!--IE内置打印控件IEWebBrowser--><OBJECT id=wb height=0 width=0 classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 name=wb></OBJECT><form><table width="600" border="1" align="center" cellpadding="0" cellspacing="0" class="STYLE1">  <tr>    <td height="17" colspan="3" bgcolor="#0099CC">>>监控信息>></td>  </tr>  <tr>    <td height="27" align="center" bgcolor="#C6C4DF">序号</td>    <td align="center" bgcolor="#C6C4DF">学校代码</td>    <td align="center" bgcolor="#C6C4DF">设备状态</td>  </tr>    <tr>    <td height="17" align="center">1</td>    <td height="17" align="center">1001</td>    <td height="17" align="center">正常</td>  </tr>  <tr class="PageNext"><!--希望人为设置分页的位置设置class="PageNext"样式-->    <td height="17" align="center">2</td>    <td height="17" align="center">1002</td>    <td height="17" align="center">正常</td>  </tr>  <tr>    <td height="17" align="center">3</td>    <td height="17" align="center">1003</td>    <td height="17" align="center">正常</td>  </tr></table><DIV align=center><!--希望打印时不显示的内容设置class="Noprint"样式--><INPUT οnclick=javascript:printit() type=button value=打印 name=button_print class="Noprint"/> <INPUT οnclick=javascript:printsetup(); type=button value=打印页面设置 name=button_setup class="Noprint" /> <INPUT οnclick=javascript:printpreview(); type=button value=打印预览 name=button_show class="Noprint" /> <input type="button" value="清空页码" οnclick=javascript:pagesetup_null() class="Noprint"><input type="button" value="恢复页码" οnclick=javascript:pagesetup_default() class="Noprint"></DIV></form></BODY></HTML>

 

转载于:https://www.cnblogs.com/liyuxin/archive/2011/03/31/2000635.html


最新回复(0)