title: JavaScript: Send raw text to printer - no server requests/method calls, able to work offline, purely clientside
body: <p>My thorough research on the web provided me with a couple of ideas, but none of them seem to work correctly in my particular use case. Here is what I have:</p>
  
  <p>1) Zebra printer, which uses ZPL as its printing language;</p>
  
  <p>2) A string in javascript which consists of 3 ZPL forms for printing 3 labels. </p>
  
  <p>Our system engineer has verified already, that the ZPL syntax is all correct.
  What I am trying to achieve is to send the string as plain text for the printer to accept it as ZPL instructions to print labels.
  The best I have come up with so far looks like this:</p>
  
  <pre><code>var mywindow = window.open('', 'Printing', 'width=800,height=600');
  //mywindow.write("testDirectWrite"); // not working
  mywindow.document.open('text/plain');
  ////mywindow.document.write('&lt;html&gt;&lt;head&gt;&lt;title&gt;Printing&lt;/title&gt;&lt;meta charset="ISO-8859-1"&gt;');
  ///*optional stylesheet*/ //mywindow.document.write('&lt;link rel="stylesheet" href="main.css" type="text/css" /&gt;');
  ////mywindow.document.write('&lt;/head&gt;&lt;body&gt;');
  var theDiv = $(".test-printirane-po-usb");
  var printContents = theDiv[0].innerText;
  mywindow.document.write(printContents);
  ////mywindow.document.write('&lt;/body&gt;&lt;/html&gt;');
  
  //mywindow.document.close(); // necessary for IE &gt;= 10
  //mywindow.focus(); // necessary for IE &gt;= 10
  
  //mywindow.print();
  //mywindow.close();
  </code></pre>
  
  <p>For now (testing purposes), theDiv is the container where i place the ZPL string. Basically, I understood, that the best solution is to open a new popup window, fill it with the ZPL string and call thePopupWindow.print(); The user then selects the zebra printer and hits 'Print'.
  <strong>The problem:</strong> it seems like the printer interprets what's being printed as an html page (because of the</p>
  
  <pre><code>&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;theZPLString comes here&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>tags, that i see, when I inspect the popup in Chrome, for example) and prints the ZPL code as plain text, rather than interpret it and print a label. I suppose I need something like thePopupWindow.write() to avoid writing to the document property of the window, which obviously wraps the string in html code.
  In order to test it, I use the Generic/Text Only driver and save what's "printed" into a .txt file.</p>
  
  <p>In Chrome I get an empty file.</p>
  
  <p>In Mozilla, when I remove this line: mywindow.document.open('text/plain'); I get the ZPL as characters, one per line. When I add it, I get only a date and time, again one char per line.</p>
  
  <p>In IE - I get this (with or without mywindow.document.open('text/plain');):</p>
  
  <pre><code>Page 1 o
  
  
  
      ^XA^PW400^LL37^
  
  
  
  
  
            12.4.2016
  </code></pre>
  
  <p>I found various solutions, but they involve using php, c#, even java and I don't want it to be server-side, as mentioned in the title.
  Any help will be appreciated.
  @forgivenson, thanks for the point. After reading yours, I saw the little 'x', that I can click to delete my comment, so I added the comment within the question.
  I missed something very important: the printer is connected via USB port!</p>