用 myDoc.listener属性就可以了:
复制内容到剪贴板
代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>事件监听</title>
<script type="text/javascript" src="jatoolsPrinter.js"></script>
<script type="text/javascript">
function doPrint(how) {
var log = document.getElementById('event-log');
log.innerHTML = '';
// 打印文档对象
var myDoc = {
listener : function(e) {
log.innerHTML += (decodeEvent(e) + '<br>');
},
documents : document, // 打印页面(div)们在本文档中
copyrights : '杰创软件拥有版权 www.jatools.com'
};
var jatoolsPrinter = getJatoolsPrinter();
// 调用打印方法
if (how == '打印预览...')
jatoolsPrinter.printPreview(myDoc, false); // 打印预览
else if (how == '打印...')
jatoolsPrinter.print(myDoc, true); // 打印前弹出打印设置对话框
else
jatoolsPrinter.print(myDoc, false); // 不弹出对话框打印
}
// 根据事件的类型,提取相应的参数
function decodeEvent(e) {
var result = e.type + ',';
if (e.type == 'window-open') {
result += '预览窗口打开';
} else if (e.type == 'window-close')
result += '预览窗口关闭';
else if (e.type == 'doc-start')
result += '开始文档打印';
else if (e.type == 'doc-stop')
result += '结束文档打印';
else if (e.type == 'page-printed') {
result += '正在打印一页,';
result += ('页号:' + e.pageNumber + ',');
result += ('总页数:' + e.totalPages);
} else if (e.type == 'printed') {
result += '打印结束';
} else if (e.type == 'cancel-print') {
result += '打印取消,';
result += '原因:' + e.error;
} else if(e.type == 'job')
{
result +=(e.printerName+' '+ e.document+' '+e.status+' '+e.statusText+' '+e.userName+' '+e.pagesPrinted+' '+e.totalPages+' '+e.size + ' ');
}
return result;
}
</script>
</head>
<body>
<input type="button" value="打印预览..." onClick="doPrint('打印预览...')">
<input type="button" value="打印..." onClick="doPrint('打印...')">
<input type="button" value="打印" onClick="doPrint('打印')"><br>
<p>事件:</p>
<p id='event-log'></p>
<div id='page1'>第一页</div>
<div id='page2'>第二页</div>
<!-- 插入打印控件 -->
<object id="ojatoolsPrinter" codebase="jatoolsPrinter.cab#version=5,4,0,0"
classid="clsid:B43D3361-D075-4BE2-87FE-057188254255" width="0" height="0">
<embed id="ejatoolsPrinter" type="application/x-vnd.jatoolsPrinter"
pluginspage="jatoolsPrinter.exe" width="0" height="0"
/>
</body>
</html>