打印指定区域,页面设置
<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="commontaglib"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>打印指定区域</title
</head>
<body>
<form name="form1" method="post" action="index.jsp">
<div id="div2">
<table width="100%" class="lindexs">
<tr>
<td align="left">
<li>
缴费成功!信息如下:
</li>
</td>
</tr>
</table>
</div>
<br />
<div id="div1">
<table width="100%" class="lindexs">
<tr bgcolor="#EDF4FC">
<td width="30%" align="right">
手机号码:
</td>
<td width="70%" align="left">
<c:property name="order.phone" />
</td>
</tr>
</table>
</div>
<table width="100%" class="lindexs">
<tr>
<th colspan="2">
<a href="javascript:printme()" target="_self">打印</a>|
<a href="javascript:window.close()">关闭</a>
<input type="submit" value=" 确认 返回 " />
</th>
</tr>
</table>
</form>
</body>
</html>
<script language="javascript">
var HKEY_Root,HKEY_Path,HKEY_Key;
HKEY_Root="HKEY_CURRENT_USER";
HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
function printme()
{
document.body.innerHTML=document.getElementById('div1').innerHTML+'<br/>'+document.getElementById('div2').innerHTML;
PageSetup_Null();
window.print();
window.history.go(0);
}
function PageSetup_Null()
{
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,"");
HKEY_Key="margin_left"
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0"); //键值设定--左边边界
HKEY_Key="margin_top"
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0.5"); //键值设定--上边边界
HKEY_Key="margin_right"
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0"); //键值设定--右边边界
HKEY_Key="margin_bottom"
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"0"); //键值设定--下边边界
}
</script>