在JQuery中关闭Modal后关闭父窗口

时间:2016-11-11 03:05:21

标签: javascript jquery html

我正在尝试关闭模态窗口时关闭父窗口。 我使用JQuery UI创建了一个自定义模态窗口,我无法关闭父窗口。

$(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()未关闭父窗口。

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

如何解决这个问题。

由于

1 个答案:

答案 0 :(得分:0)

在父窗口中创建功能

window.parent.close();