Javascript window.print() - 不打开打印窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11391178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
window.print() - without opening the print window
提问by Lea Cohen
Possible Duplicate:
“Silent” Printing in a Web Application
可能的重复:
Web 应用程序中的“静默”打印
I'd like the window.print()
command to print directly, without opening the print window:
我希望window.print()
命令直接打印,而无需打开打印窗口:
Is that possible?
那可能吗?
回答by Pranay Rana
try
尝试
For Mozilla : http://forums.mozillazine.org/viewtopic.php?t=48336
对于 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:
当您window.print()
在 IE 中使用 JavaScript打印网页时,默认情况下会提示 IE 的打印机对话框。为避免这种情况,请使用以下 JavaScript 代码:
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();
}
回答by Dor Cohen
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.
在 Firefox 的位置栏中输入 about:config 并按 Enter。
右键单击页面上的任意位置并选择“新建”>“布尔值”
输入首选项名称为 print.always_print_silent 并单击确定。
Look at the following question:
看下面的问题: