title: google chrome print preview does not load the page the first time
body: <p>I'm trying to print a page using this code</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script type="text/javascript"&gt;
          function Popup() 
          {
  
              var mywindow = window.open('', 'Ticket info', 'height=400,width=600');
              mywindow.document.write('&lt;html&gt;&lt;head&gt;&lt;title&gt;my div&lt;/title&gt;');
              mywindow.document.write('&lt;style type="text/css"&gt; *{margin: 0; padding: 0;} body{padding: 3px; padding-left:20px;font:6px bold Arial;}&lt;/style&gt;');
              mywindow.document.write('&lt;script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;'+'/script&gt;');
              mywindow.document.write('&lt;script src="jquery-barcode.min.js"&gt;&lt;'+'/script&gt;');
              mywindow.document.write('&lt;/head&gt;&lt;body&gt;');
              mywindow.document.write('&lt;div id="demo"&gt;&lt;/div&gt;');
              mywindow.document.write('&lt;script type="text/javascript"&gt;$("#demo").barcode("1234567890128", "code39");&lt;'+'/script&gt;');
              mywindow.document.write('&lt;/body&gt;&lt;/html&gt;');
              mywindow.print();
              return true;
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;input type="button" value="Print Div" onclick="Popup();" /&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Basically it will pop out a window and show a print preview of the page. the first attempt to load the print preview will not load the barcode and when you cancel the first print preview then right click the page and print again the 2nd print preview will now show the barcode to print.</p>
  
  <p><img src="https://i.stack.imgur.com/6ZnyW.png" alt="1st print attempt"></p>
  
  <p><img src="https://i.stack.imgur.com/0BKpn.png" alt="reprint"></p>
  
  <p><img src="https://i.stack.imgur.com/GsXGb.png" alt="2nd print attempt"></p>
  
  <p>I think the issue is coming from this line: </p>
  
  <pre><code>mywindow.document.write('&lt;script type="text/javascript"&gt;$("#demo").barcode("1234567890128", "code39");&lt;'+'/script&gt;');
  </code></pre>
  
  <p>when I comment this line and add a  dummy text to the page. It will automatically show up in the print preview on the first attempt.</p>
  
  <p>I had the same issue before when I'm trying to load the style from a css file. I resolve this by transferring the styles directly to the popup window. </p>
  
  <p>My question is why is this happening? and how can I load the barcode on the first attempt of the print preview?</p>