我需要为IE 6/7编写一个插件/插件,它将拦截任何Javascript print()
调用,并在默认打印机上自动打印页面,绕过标准打印对话框。不幸的是,我对Windows或IE编程知之甚少(我来自Cocoa的土地),所以我对从哪里开始有点不知所措。我想我想写一个BHO,但我不确定。非常感谢任何帮助。
我发现了一种在VBScript中实现这种效果的方法,它驻留在网页上(覆盖了Print函数),所以如果它就像在某种插件中包装那些代码一样简单,那将是理想的。
答案 0 :(得分:0)
尝试this。
if(navigator.appName == "Microsoft Internet Explorer"){
var PrintCommand = '<object ID="PrintCommandObject" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
document.body.insertAdjacentHTML('beforeEnd', PrintCommand);
PrintCommandObject.ExecWB(6, 2);
PrintCommandObject.outerHTML = "";
} else {
window.print();
}
但它在Windows XP SP2(以及Windows Server 2003 SP1或更高版本)中不起作用。
答案 1 :(得分:0)
我多年前写过和activex控件。
这是三个代码。
SendKeys( cntrl + P )
SendKeys( enter )
答案 2 :(得分:0)
我可以使用以下脚本来消除IE11中的多个打印对话框。
function callThisPrintFunction() {
var isIE11 = !!navigator.userAgent.match(/Trident.*rv[ :]*11\./);
if (navigator.appName == "Microsoft Internet Explorer" || isIE11== true) {
var PrintCommand = '<OBJECT ID="PrintCommandObject" WIDTH=0 HEIGHT=0 ';
PrintCommand += 'CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', PrintCommand);
PrintCommandObject.ExecWB(6, 2); PrintCommandObject.outerHTML = "";
window.close();
}
else {
window.print();
}
}
问题:有没有办法在Chrome / Firefox中实现这一目标?