【问题标题】:open print dialog that display only passed printer names or ip?打开仅显示传递的打印机名称或 IP 的打印对话框?
【发布时间】:2026-02-03 06:25:01
【问题描述】:

我正在尝试使用 jQuery.print.js 插件打印从 ajax 调用返回的 HTML 页面,并且一切正常,希望我需要传递打印机名称或打印机 ip 以仅显示传递的打印机以供选择一个进行打印发生了吗?

下面我会提到使用代码...

这是我的具有点击功能的锚标记

    <a href="" data-order_no = "<?php echo $rest_order->id;?>" class="table-icon-saveprint icon" style="color: green;">print</a>

这是我触发预览和打开打印对话框的功能

$(document).on( 'click', '[data-order_no] ', function(e){
       e.preventDefault();
         var order_id = jQuery(this).attr('data-order_no');
         //Print ele4 with custom options
         $.ajax({
              type: 'POST',
              url: '<?php echo base_url();?>Orders/print_order',
              data: {order_id: order_id}, //How can I preview this?
              dataType: 'html',
              success: function(result){
                  $("#test_prints").print({
                         //Use Global styles
                         globalStyles : false,
                         //Add link with attrbute media=print
                         mediaPrint : false,
                         //Custom stylesheet
                         stylesheet : "http://fonts.googleapis.com/css?family=Inconsolata",
                         //Print in a hidden iframe
                         iframe : false,
                         //Don't print this
                          noPrintSelector : "#test_prints",
                         //Add this at top
                         //Add this on bottom
                         append : result, // result are html page i want to print
                         //Log to console when printing is done via a deffered callback
                         deferred: $.Deferred().done(function() { console.log('Printing done', arguments); })
                     });
              }
            });

         });

现在我如何在使用这种方式或其他方式触发打印对话框时显示特定的打印机,我知道我正在使用 php 作为后端语言?

任何帮助,请提前致谢。

最好的,

【问题讨论】:

    标签: javascript jquery printing


    【解决方案1】:

    触发打印对话框时如何显示特定打印机?

    浏览器中的 Javascript 没有权限或任何类型的 API 来访问通常显示在打印对话框中的任何信息。

    所以很遗憾,目前无法实现此功能。

    【讨论】:

    • 感谢您的回复,我想知道是否有任何替代解决方案?