常在WEB 打印中都需要ScriptX.cab,这里也是一样,所以原理都是一样的,这里将要详细说明的是,如何控制打印的问题。
打印的必须文件有2个:
1:配置文件:setting.js
2:显示文件:print.js
setting.js 如下:
document.write("<object id=\"factory\" style=\"display:none\" viewastext classid=\"clsid:1663ed61-23eb-11d2-b92f-008048fdd814\" codebase=\"images/events/ScriptX.cab#Version=5,60,0,360\"></object>");
function Printers() {
agree = confirm('确定打印吗?');
if (agree) {
if (agree)
{
NoPrinter.style.visibility='hidden';
factory.printing.Print();}
else NoPrinter.style.visibility='visible';
}
}
factory.printing.header = ""
factory.printing.footer = ""
factory.printing.leftMargin = 0.75
factory.printing.topMargin = 0.75
factory.printing.rightMargin = 0.75
factory.printing.bottomMargin = 0.75
显示文件print.js 如下:
document.write('<style media="print">@media print { .noprint{display:none} } </style>');
/////////////////////////////////~~控制打印时不显示按钮的样式,在页面不需要打印的地方只需要引用该样式即可
document.write('<div id=NoPrinter name=NoPrinter align=right style="visibility:visible" class="noprint"><br> ');
document.write('<input type=button class=button value=关闭 name="bFQ" id="bFQ" onclick=\"javascript\:window.close()\">');
document.write('<input type="button" value="打印设置" onclick=\"factory.printing.PageSetup()\">');
document.write('<input type="button" value="打印预览" onclick=\"factory.printing.Preview()\">');
document.write('<input type=button name=button3 value="打印" onclick="Printers()"> </div>');
在使用打印功能时,只要把文件2个文件包含在页面中放置打印按钮的地方即可,代码如下:
<script src="../inc/print/Printer.js"></script>
<script src="../inc/print/Printers.js"></script>