function startprint(url) {
if (window.print && window.frames && window.frames['printerIframe']) {
var html = '';
html = '<html><head>';
html += '<object id=factory classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" viewastext="" width="0"></object>';
html += '<script language="javascript">';
html += 'function set_print(){';
html += 'try {';
html += 'execScript("document.getElementById(\'factory\').execwb 6, 2, 3", "vbscript");';
html += ' } catch (e) {';
html += 'alert("您的浏览器不支持此功能,请使用IE浏览器。");}'
html += '}<\/script>';
html += '</head><body οnlοad="parent.printFrame(window.frames[\'ToPrint\']);">';
html += '<iframe name="ToPrint" width="100%" height="100%" src="'+url+'" frameborder="no" border="0" marginwidth="0″ marginheight="0" scrolling="no" allowtransparency="yes"><\/iframe>';
html += '<\/body><\/html>';
var ifd = window.frames['printerIframe'].document;
ifd.open();
ifd.write(html);
ifd.close();
}
}
function printFrame (frame) {
if (frame.print) {
frame.focus();
window.frames['printerIframe'].set_print(); //使用页面的打印
}
}
使用时调用startprint("http://www.baidu.com");
IE 下自带打印控件,直接打印,完成测试,可用。
最新推荐文章于 2022-06-09 15:41:03 发布