Tuesday, January 27, 2015

Close Child Window from Parent Jquery

Open new window (child) from parent
 var child; //initialize as global  
   
   $('#prinBtn').button().click(function (e) {  
     child = window.open('viewtranslip.html');      
   });       
   
 //close child button   
   $('#doneBtn').button().click(function (e) {  
     e.preventDefault();  
 //check if child window is already closed  
       if (child && !child.closed){       
         child.close();       
       }        
   });       
   

Tested in IE 8, Chrome and Mozilla.
Limitation: If you open a pdf, doc, xls, in child window, this function will return a "Permission Denied" error on the child.close() line. "When Internet Explorer uses an Active Document server, such as Microsoft Word, Microsoft Excel, or Adobe Reader, to display a document in an Internet Explorer window, the page contains only the active document window and not the MSHTML. "
Read more about this limitation at http://support.microsoft.com/kb/934365/

Update: I found a fix that works in Internet Explorer, Mozilla, Chrome

No comments:

Post a Comment