用vbscript 来实现的打印,不会弹出提示框,这方法只对IE有效。function printit() {
try {
//document.all.WebBrowser.ExecWB(6,6);
execScript('document.getElementById("WebBrowser").execwb 6, 2, 3', 'vbscript');
} catch (e) {
alert("您的浏览器不支持此功能,需要5.5以上版本");
}
}
此方法会弹出选择打印机的窗口,正常情况下可用,不过很烦,只有IE下可用。
document.all.WebBrowser.ExecWB(6,1)
document.all.WebBrowser.ExecWB(6,1)
隐藏打印的问题,这方法是在网上找到的,还没有试过,主要是拼接iframe,然后打印这个iframe。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<script language="javascript">
function printURL (url) {
if (window.print && window.frames && window.frames['printerIframe']) {
var html = '';
html = '<html><head>';
html += '<object id=factory viewastext style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="smsx.cab#Version=6,4,438,06"></object>';
html += '<script language="javascript">';
html += 'function set_print(){';
html += 'factory.printing.header = "";';
html += 'factory.printing.footer = "";';
html += 'factory.printing.portrait = 1;';
html += 'factory.printing.leftMargin = 13;';
html += 'factory.printing.topMargin = 20;';
html += 'factory.DoPrint(false);';
html += '}<\/script>';
html += '</head><body onload="parent.printFrame(window.frames[\'urlToPrint\']);">';
html += '<iframe name="urlToPrint" 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.print();调用页面打印
window.frames['printerIframe'].set_print(); //使用页面的打印
}
}
</script>
</HEAD><BODY>
<iframe src="" width="0" height="0" id="printerIframe" name="printerIframe"></iframe>
<input type="button" value="tijiao" onclick="printURL('http://www.baidu.com');" />
</BODY>
</HTML>
本文介绍如何使用VBScript和JavaScript在Internet Explorer中实现网页静默打印功能,避免弹出打印机选择对话框,同时提供了一种通过iframe进行打印的方法。
2146

被折叠的 条评论
为什么被折叠?



