ScriptX打印控件的使用
===============================介绍B===================================
1.需先下载smsx.exe插件进行安装
2.将如下代码拷贝到一个scriptXprint.js文件中保存:
function setPrintBase(headerText,footerText,rootUrl) {
// -- advanced features
//factory.printing.SetMarginMeasure(2); // measure margins in inches
//factory.SetPageRange(false, 1, 3);// need pages from 1 to 3
//factory.printing.printer = "HP DeskJet 870C";
//factory.printing.copies = 2;
//factory.printing.collate = true;
//factory.printing.paperSize = "A4";
//factory.printing.paperSource = "Manual feed"
var header = (headerText==null||headerText=="")?'':'';
var footer = (footerText==null||footerText=="")?'':'';
factory.printing.header = "&b"+header+"&b" ;
factory.printing.footer = "&b"+footer;
factory.printing.portrait = true;
factory.printing.leftMargin =10.00;
factory.printing.topMargin =10.00;
factory.printing.rightMargin =10.00;
factory.printing.bottomMargin =10.00;
}
3.在需要打印的页面的head标签中加入如下代码:
<script language="javascript" src="scriptXprint.js"></script> <!-- 引入scriptXprint.js文件-->
<style media="print">
.Noprint {DISPLAY: none;} <!--设置不需要被打印的元素的样式-->
</style>
<script defer>
function window.onload() {
setPrintBase('ҳü','Ò³½Å'); <!-- 当页面加载时,设置页眉页脚需显示的内容-->
}
</script>
4.在head标签与body标签之间加入如下代码,以启动scripX.cab控件:
<OBJECT id="factory" style="DISPLAY: none" codeBase="smsx.cab#VVersion=6,3,435,20" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext></OBJECT>
5.用class="Noprint"来设置不需要被显示在打印效果中的元素的样式
6.在某个按钮或链接的单击事件上调用如下相应的函数即可:
<input type=button value="´òÓ¡" onclick="factory.printing.Print(true)">
<input type=button value="Ò³ÃæÉèÖÃ" onclick="factory.printing.PageSetup()">
<input type=button value="´òÓ¡Ô¤ÀÀ" onclick="factory.printing.Preview()">
<input type="button" value="¹Ø±Õ" onclick="window.close();">