Wednesday, January 28, 2015

Close PDF Child Window in Parent (works in IE, Mozilla, Firefox)

In my previous post, I tried to open a pdf in another window, and when user clicks Done button in the parent window, the pdf (child) window should close. I have successfully achieved this but it didn't work in Internet explorer. But Thank God! I found an alternate fix that will run both in Internet Explorer, Chrome and Mozilla.

 var child; //initialize as global
$('#printBtn').button().click(function (e) {      
     var link = 'viewtranslip.html'; //link for generating your pPDF 
     var html = "<html><head><title></title>";  
     html += "</head><body style='margin: 0;'>";  
     html += "<iframe height='100%' width='100%' src='" + link +"'></iframe>";  
     html += "</body></html>";  
     child = window.open("", "_blank", "resizable=1,status=0,toolbar=0,menubar=0");  
     child.document.write(html);  
     return win;  
 });     

 //close child button   
   $('#doneBtn').button().click(function (e) {  
     e.preventDefault();  
 //check if child window is already closed  
       if (child && !child.closed){       
         child.close();       
       }        
   });
  

No comments:

Post a Comment