2016-11-11 84 views
0

我试图在模态窗口关闭时关闭父窗口。 我创建了一个使用JQuery UI的自定义模态窗口,我无法关闭父窗口。在JQuery中关闭Modal后关闭父窗口

$(document).ready(function() {   
     dialog = $("#dialog").dialog({ 
      autoOpen: false, 
      height: 300, 
      width: 500, 
      modal: true, 
      buttons: { 
       "Approve": addUser, 
       Cancel: function() { 
        dialog.dialog("close"); 
       } 
      } 
     }); 

     }); 

function addUser() { 

      var getJSON = function (url) { 
       return new Promise(function (resolve, reject) { 
        var xhr = new XMLHttpRequest(); 
        xhr.open('get', url, true); 
        xhr.withCredentials = true; 
        xhr.onload = function() { 
         var status = xhr.status; 
         if (status == 200) { 
          resolve(xhr.response); 
         } else { 
          reject(status); 
         } 
        }; 
        xhr.send(); 
       }); 
      }; 

      getJSON(url).then(function (data) { 
       var result = "Approved Successfully" 
       dialog.dialog("close");      
       alert(result); 
       window.close(); ///Here, the PARENT Window is not closing 

      }, function (status) { //error detection.... 
       alert('Something went wrong.'); 
      }); 
} 

在这里,我的模式对话框被关闭,但window.close()的不打烊的父窗口。

我收到一条消息“脚本可能只关闭通过它打开的窗口。”

如何解决这个问题。

感谢

回答

0

创建父窗口功能

window.parent.close();