window.print() - without opening the print window [duplicate]

陌路散爱 提交于 2019-12-17 12:36:29

问题


Possible Duplicate:
“Silent” Printing in a Web Application

I'd like the window.print() command to print directly, without opening the print window:

Is that possible?


回答1:


try

For Mozilla : http://forums.mozillazine.org/viewtopic.php?t=48336

When you use JavaScript's window.print() to print a Web page in IE, by default, it prompts IE's printer dialog box. To avoid this, use the following JavaScript code:

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, -1); PrintCommandObject.outerHTML = "";
}
else {
window.print();
}

from : http://www.devx.com/tips/Tip/30834




回答2:


It called silent printing and you can do it on several browsers but it isn't that simple..

On Fire Fox -

Type about:config at Firefox’s location bar and hit Enter.

Right click at anywhere on the page and select New > Boolean

Enter the preference name as print.always_print_silent and click OK.

Look at the following question:

"Silent" Printing in a Web Application



来源:https://stackoverflow.com/questions/11391178/window-print-without-opening-the-print-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!