简体   繁体   中英

automatically printing page on form submit

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 (ie internet explorer web page printing defaults).

<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

There is no way 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

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM