javascript - Direct Print after clicking - Stack Overflow

I am using a JS function in my POS website which is:<script type="textjavascript">fun

I am using a JS function in my POS website which is:

<script type="text/javascript">
function printlayer(layer){
  var generator=window.open(",'name,");
  var layertext=document.getElementById(layer);
  generator.document.write(layertext.innerHTML.replace('Print Me'));
  generator.document.close();
  generator.print();
  generator.close();
}

When I click on Print button, it opens a new Print tab on screen but I want to print directly. Suppose I clicked on print, it should print directly. "IT SHOULD NOT OPEN THE PRINT TAB". I am using Thermal Receipt Printer: GPrinter Modal is: GP80160II Paper width: 80mm Print Speed: 160mm/sec.

This Picture is before clicking Print:

This Picture is After clicking (That I don't want): Please Help me. I am not able to do this. Thanks in advance

I am using a JS function in my POS website which is:

<script type="text/javascript">
function printlayer(layer){
  var generator=window.open(",'name,");
  var layertext=document.getElementById(layer);
  generator.document.write(layertext.innerHTML.replace('Print Me'));
  generator.document.close();
  generator.print();
  generator.close();
}

When I click on Print button, it opens a new Print tab on screen but I want to print directly. Suppose I clicked on print, it should print directly. "IT SHOULD NOT OPEN THE PRINT TAB". I am using Thermal Receipt Printer: GPrinter Modal is: GP80160II Paper width: 80mm Print Speed: 160mm/sec.

This Picture is before clicking Print:

This Picture is After clicking (That I don't want): Please Help me. I am not able to do this. Thanks in advance

Share Improve this question edited Jan 26, 2019 at 7:57 Kami asked Jan 26, 2019 at 7:42 KamiKami 431 gold badge1 silver badge7 bronze badges 9
  • You are calling window.open(). If you want to print directly, don't do that. Just call print(). If necessary, hide everything you don't want to print, for instance by using @media rules. – user5734311 Commented Jan 26, 2019 at 7:44
  • @ChrisG I tried .print also, but there are some issues. It shows popup print screen – Kami Commented Jan 26, 2019 at 7:49
  • @ChrisG see my question now. I Added Pictures now. – Kami Commented Jan 26, 2019 at 7:58
  • I created a PHP app for a friend to print A4 invoices; the key is to use CSS like width: 19cm so the screen document translates 1:1 to paper. – user5734311 Commented Jan 26, 2019 at 8:00
  • That is how chrome works and how any other browser would. You can't do anything about it – Ikhlak S. Commented Jan 26, 2019 at 8:03
 |  Show 4 more ments

1 Answer 1

Reset to default 3

If you are using IE browser then this can be achieved. But in firefox and chrome we can't bypass the dialogue box. You can avoid the print dialog from any application by using some cloud printing REST API.

Select a printer and silently print(SO)

https://developers.google./cloud-print/docs/appInterfaces

https://www.printnode./docs/api/curl/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742347078a4426760.html

相关推荐

  • javascript - Direct Print after clicking - Stack Overflow

    I am using a JS function in my POS website which is:<script type="textjavascript">fun

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信