jsp页面打印方法
来源:互联网 发布:q版画像软件 编辑:程序博客网 时间:2024/05/01 22:53
JSP页面打印方法
方法一:
function PrintTable(Id){
var mStr;
mStr = window.document.body.innerHTML ;
var mWindow = window;
window.document.body.innerHTML =Id.innerHTML;
mWindow.print();
window.document.body.innerHTML = mStr;
}
在页面中要打印
<div id="dy">
.......
</div>
<input type="button" value="打 印" onclick="return PrintTable(dy)">
方法二:
/*-----------print.js
Copyright (c) 2002,*************
All rights reserved.
Filename :print.js
Abstract :常用打印函数
Version :1.0
Author :Liu Guoyuan
Finished Date :2003-03-19
Last Modified :2003-03-20
-------------------------------------------------------------------------------------
*/
with (document)
{//输出样式表表及IE打印控件
write ("<style type=/"text/css/" media=/"print/">");
write (" .noPrint{visibility:hidden}");
write ("</style>");
write ("<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WB width=0></object>");
}
function doPrintSetup()
{//打印设置
WB.ExecWB(8,1);
}
function doPrintPreview()
{//打印预览
WB.ExecWB(7,1);
}
function doPrint()
{
window.print();
}
function showPrintBar()
{
with (document)
{
write ("<div align=/"center/" class=/"noprint/">");
write (" <input type=/"button/" name=/"doBack/" value=/" <<返回 /" onClick=/"history.go(-1)/">");
write (" <input type=/"button/" name=/"doPrintPreview/" onClick=/"WB.ExecWB(8,1)/" value=/"打印设置/">");
write (" <input type=/"button/" name=/"doPrint/" value=/" 打印>> /" onClick=/"doPrint()/">");
write ("</div>")
}
}
----------------print.js end------------
页面中使用时:
<script language="JavaScript" type="text/JavaScript" src="print.js"></script>
然后再需要输出打印按钮时:
<script>showPrintBar()</script>
方法三:
打印前把按钮隐藏
<tr><td><input type="button" value="打 印" name="butt" onClick="javascript:hide()"></td></tr>
<script language="javascript">
function hide()
{
document.all.item("butt").style.display="none";
window.print();
}
</script>
方法四:
<style>
@media print{
.noprint{display:none}
}
</style>
给不打印的区加这个CSS就可以了,在页面上能看见但打印的时候看不到!
方法五:
利用脚本控制打印,可以采用如下方法:
1、execCommand()方法
Print 打开打印对话框以便用户可以打印当前页
即document.execCommand('Print');
2、window.print()
3、 <OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
<input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)>
方法六:
<%@ page contentType="text/html; charset=GBK"%>
<%
String url="#"
%>
<style media="print">
.noPrint { display: none }
</style>
<style media="screen">
.print { display: none }
</style>
<html>
<title></title>
<body>
<jsp:include page="<%=url%>" />
<table width="100%" class="noPrint" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="60" align="center">
<input type=button name=button_show value="打 印" onclick="print();">
<input type=button name=button_show value="打印预览" onclick="preview();">
<input type=button name=button_setup value="打印设置" onclick="pageSetup();">
</td>
</tr>
</table>
</body>
<object id="factory" style="display:none" viewastext
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="/etsc/ActiveX/ScriptX.zip#Version=6,1,430,5">
</object>
<script language="javascript" >
function pageSetup()
{
factory.printing.PageSetup();
}
function preview()
{
setPageInfo();
factory.printing.Preview();
}
function print()
{
setPageInfo();
factory.printing.Print(true);
}
function setPageInfo(){
//factory.printing.header = "&b&b第&p页/共&P页"
//factory.printing.footer = "&b&b时间:&D&T"
factory.printing.footer = ""
factory.printing.leftMargin = 10
factory.printing.topMargin = 20
factory.printing.rightMargin = 10
factory.printing.bottomMargin = 20
}
</script>
</html>
方法一:
function PrintTable(Id){
var mStr;
mStr = window.document.body.innerHTML ;
var mWindow = window;
window.document.body.innerHTML =Id.innerHTML;
mWindow.print();
window.document.body.innerHTML = mStr;
}
在页面中要打印
<div id="dy">
.......
</div>
<input type="button" value="打 印" onclick="return PrintTable(dy)">
方法二:
/*-----------print.js
Copyright (c) 2002,*************
All rights reserved.
Filename :print.js
Abstract :常用打印函数
Version :1.0
Author :Liu Guoyuan
Finished Date :2003-03-19
Last Modified :2003-03-20
-------------------------------------------------------------------------------------
*/
with (document)
{//输出样式表表及IE打印控件
write ("<style type=/"text/css/" media=/"print/">");
write (" .noPrint{visibility:hidden}");
write ("</style>");
write ("<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WB width=0></object>");
}
function doPrintSetup()
{//打印设置
WB.ExecWB(8,1);
}
function doPrintPreview()
{//打印预览
WB.ExecWB(7,1);
}
function doPrint()
{
window.print();
}
function showPrintBar()
{
with (document)
{
write ("<div align=/"center/" class=/"noprint/">");
write (" <input type=/"button/" name=/"doBack/" value=/" <<返回 /" onClick=/"history.go(-1)/">");
write (" <input type=/"button/" name=/"doPrintPreview/" onClick=/"WB.ExecWB(8,1)/" value=/"打印设置/">");
write (" <input type=/"button/" name=/"doPrint/" value=/" 打印>> /" onClick=/"doPrint()/">");
write ("</div>")
}
}
----------------print.js end------------
页面中使用时:
<script language="JavaScript" type="text/JavaScript" src="print.js"></script>
然后再需要输出打印按钮时:
<script>showPrintBar()</script>
方法三:
打印前把按钮隐藏
<tr><td><input type="button" value="打 印" name="butt" onClick="javascript:hide()"></td></tr>
<script language="javascript">
function hide()
{
document.all.item("butt").style.display="none";
window.print();
}
</script>
方法四:
<style>
@media print{
.noprint{display:none}
}
</style>
给不打印的区加这个CSS就可以了,在页面上能看见但打印的时候看不到!
方法五:
利用脚本控制打印,可以采用如下方法:
1、execCommand()方法
Print 打开打印对话框以便用户可以打印当前页
即document.execCommand('Print');
2、window.print()
3、 <OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
<input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)>
方法六:
<%@ page contentType="text/html; charset=GBK"%>
<%
String url="#"
%>
<style media="print">
.noPrint { display: none }
</style>
<style media="screen">
.print { display: none }
</style>
<html>
<title></title>
<body>
<jsp:include page="<%=url%>" />
<table width="100%" class="noPrint" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="60" align="center">
<input type=button name=button_show value="打 印" onclick="print();">
<input type=button name=button_show value="打印预览" onclick="preview();">
<input type=button name=button_setup value="打印设置" onclick="pageSetup();">
</td>
</tr>
</table>
</body>
<object id="factory" style="display:none" viewastext
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="/etsc/ActiveX/ScriptX.zip#Version=6,1,430,5">
</object>
<script language="javascript" >
function pageSetup()
{
factory.printing.PageSetup();
}
function preview()
{
setPageInfo();
factory.printing.Preview();
}
function print()
{
setPageInfo();
factory.printing.Print(true);
}
function setPageInfo(){
//factory.printing.header = "&b&b第&p页/共&P页"
//factory.printing.footer = "&b&b时间:&D&T"
factory.printing.footer = ""
factory.printing.leftMargin = 10
factory.printing.topMargin = 20
factory.printing.rightMargin = 10
factory.printing.bottomMargin = 20
}
</script>
</html>
- jsp页面打印方法
- jsp打印页面方法
- JSP页面打印方法
- jsp页面实现打印原图的方法
- JSP页面打印
- 打印JSP页面
- jsp页面打印功能
- JSP页面打印
- jsp页面实现打印
- jsp页面打印
- jsp页面打印功能
- JSP页面打印
- JSP页面打印
- jsp页面实现打印 .
- JSP页面打印
- JSP小结-页面打印
- jsp打印表格方法
- jsp打印表格方法
- ORA-01653: unable to extend table string.string by string in tablespace string
- VB Timer时钟的准确性
- Bash 实例
- 越来越强大的SAFS/STAF/STAX自动化测试框架
- WINFORM播放WAV
- jsp页面打印方法
- struts学习总结1
- 当今股市深层分析,不错的文章,推荐给大家
- [转帖]一段真实在个人经历, 给那些迷失方向的朋友
- INT 13中断功能
- 替换 Windows CE 的桌面
- Spring源代码分析(10)---ProxyFactoryBean(旁敲侧击的AOP时代终于来临)
- 从内存中加载并运行exe
- 恋爱靠感觉