IE打印frame中内容的功能

下面是2个例子,只要部署到TOMCAT中,就可以运行

index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<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 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,"");
}catch(e){
alert(e);
}
}
//恢复网页打印的页眉页脚
function PageSetup_default(){
try {
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");
}catch(e){
alert(e);
}
}

function printsetup(){
PageSetup_Null();
// 打印页面设置
wb.execwb(8,1);
}

function printpreview() {
var win = document.frames('report');
win.focus();
win.wb1.execwb(7,1);// 打印预览
}

function printit() {
if (confirm('确定打印吗?')) {
PageSetup_Null();
var win = document.frames('report');
win.focus();
win.print();
PageSetup_default();
}
}

function excel(){
window.open(document.frames('report').location.href+"&reportType=excel");
}
</script>

<body>
<object classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></object>
<input type=button name=button_print value="打印"
onclick="javascript:printit()" />
<input type=button name=button_setup value="设置"
onclick="javascript:printsetup();" />
<iframe name="report" id="report" src="main.jsp" width="100%"
height="700px"
style="marginwidth: 110px; marginheight: 110px; background-color: grey; border: 5px solid #ddd"
frameborder="0"> </iframe>
</body>
</html>



main.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>Insert title here</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<input type="text" value="phl"/><br/>
<input type="password" value="123456"/><br/>
<input type="submit" name="Submit" value="提交" />
</form>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值