window.print() - 不打开打印窗口 [英] window.print() - without opening the print window

查看:103
本文介绍了window.print() - 不打开打印窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<块引用>

可能的重复:

在IE中使用JavaScript的window.print()打印网页时,默认会提示IE的打印机对话框.为避免这种情况,请使用以下 JavaScript 代码:

if (navigator.appName == "Microsoft Internet Explorer"){var PrintCommand = '<object ID="PrintCommandObject" WIDTH=0 HEIGHT=0CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';document.body.insertAdjacentHTML('beforeEnd', PrintCommand);PrintCommandObject.ExecWB(6, -1);PrintCommandObject.outerHTML = "";}别的 {窗口.打印();}

来自:http://www.devx.com/tips/Tip/30834

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?

解决方案

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

这篇关于window.print() - 不打开打印窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆