title: content only appears if print is called twice javascript
body: <p>I'm currently trying be able to print something to the screen using javascript. Right now, I've got a simple print function set up like below that gets triggered on a link press in HTML.</p>
  <pre><code>   function print() {
          console.log(printImgURL);
          let w = window.open();
          w.document.write(`&lt;img src=&quot;${printImgURL}&quot;&gt;`);
          w.focus();
          w.print();
          w.close();
      }
  </code></pre>
  <pre><code>&lt;a id=&quot;printButton&quot; onclick=&quot;print()&quot;title=&quot;Print&quot;&gt;&lt;/a&gt;
  </code></pre>
  <p>The content only appears when the link is pressed the second time (and any other time after), Although the console.log statement shows the proper URL to the image regardless if the image actually appears in the print dialogue or not. Does anyone have any idea why the content wouldn't be showing up the first the link is pressed?</p>