{"id":399,"date":"2022-08-30T15:00:42","date_gmt":"2022-08-30T15:00:42","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/chrome-doesnt-print-javascript-content-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:00:42","modified_gmt":"2022-08-30T15:00:42","slug":"chrome-doesnt-print-javascript-content-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/chrome-doesnt-print-javascript-content-collection-of-common-programming-errors\/","title":{"rendered":"Chrome: doesn&#39;t print javascript content-Collection of common programming errors"},"content":{"rendered":"<p>( This is through Grease\/Tampermonkey ).<\/p>\n<p>Here&#8217;s a print function for a kiosk using the Chrome beta browser:<\/p>\n<pre><code>$(\"#autoCheckOrder button\").click ( function () {\n    var newWin      = window.open (\"\"); \n    newWin.document.write ( \"\" );\n    newWin.document.write( \"\" );\n    newWin.document.write( \"\" );\n    newWin.document.write( \"\" );\n    newWin.document.write( \"\" );\n    newWin.document.write( \"\" );\n    newWin.document.write( \"@media print { \" );\n    newWin.document.write( \"body { \" );\n    newWin.document.write( \"background-color: white;\" );\n    newWin.document.write( \"width: 55mm;\" );\n    newWin.document.write( \"position: absolute;\" );\n    newWin.document.write( \"top: 0;\" );\n    newWin.document.write( \"left: 0;\" );\n    newWin.document.write( \"padding: 0px;\" );\n    newWin.document.write( \"font-size: 14px;\" );\n    newWin.document.write( \"line-height: 18px;\" );\n    newWin.document.write( \"}\" );\n    newWin.document.write( \"}\" );\n    newWin.document.write( \"\" );\n    newWin.document.write( \"\" );\n    newWin.document.write( \"\" );\n    newWin.document.write ( loanHTML ); \n    newWin.document.write( \"\" );\n    newWin.document.write( \"\" );\n    if(newWin.print()) {\n        newWin.close();\n    } else {\n        newWin.close();\n    }\n});\n<\/code><\/pre>\n<p>It grabs a table from the a page listing all items, then creates a &#8216;receipt&#8217;. The receipt is then printed. This worked perfectly for a while, now it only prints the first item.<\/p>\n<p>I have tried the following with absolutely no results:<\/p>\n<ul>\n<li>Using page-break-after: always<\/li>\n<li>Placing receipt in div with the above CSS rule<\/li>\n<li>Reinstalling the printer<\/li>\n<li>Paper reduction settings for printer<\/li>\n<\/ul>\n<p>The crazy thing is that it used to print all items flawlessly and now it doesn&#8217;t. I even re-installed the script from a backup just to be sure.<\/p>\n<p>No idea where to go from here. All content shows in print preview, but only the first item prints. &#8216;Header and footer&#8217; setting only makes things worse, not better.<\/p>\n<p><strong>UPDATE<\/strong><\/p>\n<p>I changed the HTML sent to the printer and it works. Still not sure if it&#8217;s entirely valid but it&#8217;s printing. I&#8217;ll know what to fix if it stops printing. Thanks for the input!<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 18:56:49. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>( This is through Grease\/Tampermonkey ). Here&#8217;s a print function for a kiosk using the Chrome beta browser: $(&#8220;#autoCheckOrder button&#8221;).click ( function () { var newWin = window.open (&#8220;&#8221;); newWin.document.write ( &#8220;&#8221; ); newWin.document.write( &#8220;&#8221; ); newWin.document.write( &#8220;&#8221; ); newWin.document.write( &#8220;&#8221; ); newWin.document.write( &#8220;&#8221; ); newWin.document.write( &#8220;&#8221; ); newWin.document.write( &#8220;@media print { &#8221; ); newWin.document.write( [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-399","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=399"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/399\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}