日期:2014-05-16  浏览次数:20429 次

JSP页面打印方法(一)

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)">

方法二:

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就可以了,在页面上能看见但打印的时候看不到