0

I wrote the below code to print the screen. It is working fine. And it is opening the pdf file also. But behind the pdf file one window is opening. that window will open when we press on pdf file. The problem with that pdf behind window is it is becoming editable. How to remove the behind window.

angular.element('#hideLeftLinks').addClass("no-print");
var printContents = angular.element('#Print').html();
var popupWin = window.open('', '_blank', 'width=1000,height=1000');
popupWin.document.open();
popupWin.document.write('<html><head><link rel="stylesheet" type="text/css" href="css/Copyofstyles.css" /></head><body onload="window.print()">' + printContents + '</body></html>');
popupWin.document.close();
popupWin.innerHTML='';  
angular.element('#hideLeftLinks').removeClass("no-print");
Sangbok Lee
  • 2,132
  • 3
  • 15
  • 33
Balu Krish
  • 53
  • 7

1 Answers1

0

You should check this answer. I tested myself and it seems that the answer is the only one working answer for now. I removed onload="window.print()" and added <script>window.print(); setTimeout(window.close, 0);</script> and it worked. No need for popupWin.document.close(); and probably popupWin.innerHTML=''; too. So, replace below three lines

popupWin.document.write('<html><head><link rel="stylesheet" type="text/css" 
    href="css/Copyofstyles.css" /></head><body onload="window.print()">' + printContents + 
    '</body></html>');
popupWin.document.close();
popupWin.innerHTML=''; 

to

popupWin.document.write('<html><head><link rel="stylesheet" type="text/css" 
    href="css/Copyofstyles.css" /></head><body>' + printContents + 
    '<script>window.print(); setTimeout(window.close, 0);</script></body></html>');
Community
  • 1
  • 1
Sangbok Lee
  • 2,132
  • 3
  • 15
  • 33
  • In above code working fine but behind window still opening,could you provide any stuff to close behind window. – Shiva Goud A Apr 02 '17 at 07:08
  • Of course, it's opening. If it does not open, one cannot print the page. The problem is 'the window not closing after pressing Print or Cancel button'. – Sangbok Lee Apr 02 '17 at 10:40