0

I'm using the following sample code which prints locally when clicking the button, but would like it to print automatically when the page loads.

Here is the sample code:

        <script>
            $(document).ready(function () {
                $("#printBtn").click(function () {
                    //1. perform server side task
                    $.ajax({
                        url: "CreateTextFileHandler.ashx", success: function (txtFileName) {
                            alert("The text file: " + txtFileName + " was created at server side. Continue printing it...");

                            //2. Print the created text file specifying the file name

                            jsWebClientPrint.print('useDefaultPrinter=' + $('#useDefaultPrinter').attr('checked') + '&printerName=' + $('#installedPrinterName').val() + '&txtFileName=' + txtFileName);


                        }
                    });
                });
            });
        </script>

I want to change it by removing the $("#printBtn").click(function() so it will run without user intervention after the page loads. When I do the CreateTextFileHandler.ashx executes and the alert executes, but the call to jsWebClientPrint does not excecute.

matthias_h
  • 11,356
  • 9
  • 22
  • 40
mnicks
  • 25
  • 5
  • How is `jsWebClientPrint` initialized? How do you know whether it is ready? – Serendipity Mar 22 '20 at 13:21
  • Following the script above: <%-- Register the WebClientPrint script code --%> <%=Neodynamic.SDK.Web.WebClientPrint.CreateScript(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/WebClientPrintAPI.ashx", HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port + "/PrintTXTHandler.ashx", HttpContext.Current.Session.SessionID)%> – mnicks Mar 22 '20 at 13:27
  • For me that looks like server side code. My question is essentially how do you know whether jsWebClientPrint has initialized before document load? If you can solve the initialization problem, you can remove your print button scenario. Put that in a try-catch block and see if you are noticing an error. – Serendipity Mar 22 '20 at 14:02

0 Answers0