2016-11-11 83 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();