打印指定區域的一個例子

打印指定區域,頁面設置
<%@ 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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章