Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am trying to tweak or change a line of coding that allows me to print to a receipt on Android using a third party app. The third party app only understands the below code. Thanks in advance.

JavaScript
function sendToQuickPrinter(){
    var text = "test printerBig title";
    var textEncoded = encodeURI(text);
    window.location.href="quickprinter://"+textEncoded;
}


How can i use both above and bottom code combined so that the quickprinter:// understands the container and able to print onto my receipt without using any additional files. Thanks again

Java
jQuery(".invoice-print-button-container").on("click", function(){
     var printWindow = window.open("", "PRINT", "height=400,width=600");
     printWindow.document.write(""+ jQuery(".invoice-order-id").text()  + "");
     printWindow.document.write("");
     printWindow.document.write("");
     printWindow.document.write(""+jQuery(".invoice-main-wrapper").html()+"");
     printWindow.document.write("");
     printWindow.document.close(); // necessary for IE >= 10
     printWindow.focus(); // necessary for IE >= 10*-/
     printWindow.addEventListener("load", function(){
         printWindow.print();
         printWindow.close();
     }, true);
     return true;
 });


What I have tried:

I have tried the below code but the receipt paper comes out but it doesn't display the container information that i need.

JavaScript
jQuery(".invoice-print-button-container").on("click", function(){
    var printWindow = window.open("", "PRINT", "height=400,width=600");
      printWindow.document.write(""+ jQuery(".invoice-order-id").text()  + "");
      printWindow.document.write("");
      printWindow.document.write("");
      printWindow.document.write(""+jQuery(".invoice-main-wrapper").html()+"");
      printWindow.document.write("");
      var textEncoded = encodeURI(printWindow.document.write);
      window.location.href="quickprinter://"+textEncode;`
Posted
Updated 22-Nov-17 11:24am
v2
Comments
Richard Deeming 22-Nov-17 12:43pm    
You'll need to read the documentation for the third-party app.

1 solution

how can i insert the following html lines into jquery? Thanks for the advice/help in advance

HTML
<html><head><title>"+ jQuery(".invoice-order-id").text()  + "</title>
<link media='all' href='"+posStylesheetUrl+"' type='text/css' rel='stylesheet'>
</head><body>
<div class='invoice-container'><div class='invoice-main-wrapper'>"+jQuery(".invoice-main-wrapper").html()+"</div></div>
</body></html>


How can i insert the above html codes into the below coding, do i need to decode before i encode? The printer actually showing the html code on the paper for var text.

JavaScript
jQuery(".invoice-print-button-container").on("click", function(){
 
var text = ("test text here for printer"+"more text"+'≪/body></html>');

    window.location.href="quickprinter://"+text;

 
});
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900