javascript 表单提交时自动打印页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4338353/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 11:04:46  来源:igfitidea点击:

automatically printing page on form submit

phpjavascript

提问by methuselah

i have been using the below code to automatically print out a form on submission but the problem i have encountered is that upon navigating away from the page, the "Submit - And Print" button stops working.

我一直在使用下面的代码在提交时自动打印出表单,但我遇到的问题是在离开页面时,“提交 - 并打印”按钮停止工作。

Secondly is there a way to bypass the print dialog on internet explorer/google chrome and allow the form to print automatically and the send the request to the printer automatically? there is also a need to remove all headers and footers from the pages pritned (i.e. internet explorer web page printing defaults).

其次,有没有办法绕过 Internet Explorer/谷歌浏览器上的打印对话框并允许表单自动打印并自动将请求发送到打印机?还需要从打印的页面中删除所有页眉和页脚(即 Internet Explorer 网页打印默认设置)。

<html>
<head>
<script language="javascript" type="text/javascript">

function PrintMeSubmitMe()
{
window.print();
SubmitMe();
}

function SubmitMe()
{
document.MyForm.submit();
}
</script>
</head>
<body>
<form name="MyForm" action="somepage.asp" method="post">
<input type="button" value="Submit - No Print" onclick="SubmitMe()"><br />
<input type="button" value="Submit - And Print" onclick="PrintMeSubmitMe(this)"><br />
</form>
</body>
</html>


i have come to realise that the "submit - and print" bug occurs on google chrome only and not internet explorer

我开始意识到“提交和打印”错误仅发生在谷歌浏览器上,而不是 Internet Explorer

回答by Matt Ball

There is noway to bypass the print dialog.* If there was a way, it could be maliciously exploited far too easily. It would be a security nightmare.

没有办法绕过打印对话框。*如果有一种方式,它可以被恶意利用太容易。这将是一场安全噩梦



*Without a browser plugin

*没有浏览器插件

回答by Ravi Menon

On IE you can install a plugin from MeadCo(a UK based company) which includes an embedded object and comprehensive javascript interface to the printer that allows control of almost all aspects of printing. We have been using this solution for many years now and it would probably meet your needs of avoiding the print dialog, managing header/footer, etc.

在 IE 上,您可以安装来自MeadCo(一家英国公司)的插件,其中包括一个嵌入式对象和全面的 javascript 打印机接口,可以控制打印的几乎所有方面。我们已经使用这个解决方案很多年了,它可能会满足您避免打印对话框、管理页眉/页脚等的需求。

回答by new question

If you are using chrome, you can disable print preview dialog.

如果您使用的是 chrome,则可以禁用打印预览对话框。

1. Create shortcut of chrome
2. Go to properties
3. Add "--disable-print-preview" at the end of target
   or
   Add "--koisk-printing" at the end of target