title: Print a div without opening up a new Window in AngularJS
body: <p>I need to print the contents of a <code>div</code> using a <code>button</code>. I have searched it and found the way out, to do it in AngularJS.</p>
  
  <p>My issue is whenever print is invoked, it also opens up a new window; it shouldn't open it up.</p>
  
  <p>Is there a way to block the opening of the new window?</p>
  
  <p>Code below:</p>
  
  <p><strong>JS:</strong></p>
  
  <pre><code>$scope.printControl = function(id) {
      var printContents = document.getElementById(id).innerHTML;
      var popupWin = $window.open('', '_blank', 'width=800,height=800');
      popupWin.document.open();
      popupWin.document.write('&lt;html&gt;&lt;body onload="window.print()"&gt;' + printContents + '&lt;/body&gt;&lt;/html&gt;');
      popupWin.document.close();
  };    
  </code></pre>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;div id="printDiv"&gt;
      This div needs to be printed
    &lt;/div&gt;
    &lt;button ng-click="printControl('printDiv')"&gt;
    Print
  &lt;/button&gt;
  </code></pre>
  
  <p><a href="https://jsfiddle.net/nomp0ee8/" rel="nofollow"><strong>Demo</strong></a></p>