PopUp没有从父级关闭

时间:2016-10-17 12:32:21

标签: javascript jquery html

我在关闭弹出窗口时遇到问题。我的问题是独一无二的,如果我从父母点击Logout,它会关闭所有窗口,但是当我从一个孩子退出时,我将从Parent注销,因此它不会关闭其他打开的子窗口。

当我从一个孩子退出然后我从父母退出时,我检查了控制台,它没有进入if区块。

我打开所有这样的弹出窗口 -

function openpop1() {
    sessionId = getURLParameters('requestID');
    userName = getURLParameters('userName');
    userId = getURLParameters('userId');
    lvalue = getURLParameters('lValue');
    lver = getURLParameters('lVer');
    window.name = "parent";
    var intWidth = screen.width - 10; //Adjust for the end of screen 
    var intHeight = screen.height - 80; //Adjust for the Icon Bar at the bottom of the window.
    var strWinProp = " toolbar=no"         //Back, Forward, etc...
                   + ",location=no"      //URL field
                   + ",directories=no"   //"What's New", etc...
                   + ",status=yes"       //Status Bar at bottom of window.
                   + ",menubar=no"       //Menubar at top of window.
                   + ",resizable=yes"     //Allow resizing by dragging.
                   + ",scrollbars=yes"   //Displays scrollbars is document is larger than window.
                   + ",titlebar=yes"     //Enable/Disable titlebar resize capability.
                   + ",width="+intWidth    //Standard 640,800/788, 800/788
                   + ",height="+intHeight  //Standard 480,600/541, 600/566               
                   + ",top=0"              //Offset of windows top edge from screen.
                   + ",left=0"             //Offset of windows left edge from screen.
                   + "";  
     awin = window.open(aUrl + userName + "&requestID=" + sessionId
            + "&userId=" + userId + "&lValue=" + lvalue + "&lVer=" + lver,'_blank',strWinProp);
}
function openpop2() {
    sessionId = getURLParameters('requestID');
    userName = getURLParameters('userName');
    userId = getURLParameters('userId');
    lvalue = getURLParameters('lValue');
    lver = getURLParameters('lVer');
    window.name = "parent";
    var intWidth = screen.width - 10; //Adjust for the end of screen 
    var intHeight = screen.height - 80; //Adjust for the Icon Bar at the bottom of the window.
    var strWinProp = " toolbar=no"         //Back, Forward, etc...
                   + ",location=no"      //URL field
                   + ",directories=no"   //"What's New", etc...
                   + ",status=yes"       //Status Bar at bottom of window.
                   + ",menubar=no"       //Menubar at top of window.
                   + ",resizable=yes"     //Allow resizing by dragging.
                   + ",scrollbars=yes"   //Displays scrollbars is document is larger than window.
                   + ",titlebar=yes"     //Enable/Disable titlebar resize capability.
                   + ",width="+intWidth    //Standard 640,800/788, 800/788
                   + ",height="+intHeight  //Standard 480,600/541, 600/566               
                   + ",top=0"              //Offset of windows top edge from screen.
                   + ",left=0"             //Offset of windows left edge from screen.
                   + "";  
     bwin = window.open(bUrl + userName + "&requestID=" + sessionId + "&userId="
            + userId + "&lValue=" + lvalue + "&lVer=" + lver,'_blank',strWinProp);
}

登出时我正在打电话

function onLogout() {
    if (awin && !awin.closed) {
        awin.close();
    }
    if (bwin && !bwin.closed) {
        bwin.close();
    }       

    sessionId = getURLParameters('requestID');
    var rcvReq = getXmlHttpRequestObject();
    rcvReq.onreadystatechange = function() {
        if (rcvReq.readyState == 4 || rcvReq.readyState == 0) {
            var data = rcvReq.status;
        }
    }
    rcvReq.open("GET", logoutUrl +sessionId, true);
    rcvReq.send(null);
    window.location = loginPageUrl;
}

现在我的问题是为什么当我从孩子和父母退出时它不会进入if区块。我通过在这些行中添加断点来检查这一点。

    if (awin && !awin.closed) {
        awin.close();
    }
    if (bwin && !bwin.closed) {
        bwin.close();
    }       

有没有人有任何想法。请帮帮我。我不明白为什么它不能满足if条件。

1 个答案:

答案 0 :(得分:0)

只有当awin和bwin对弹出窗口有有效引用时,才会执行此代码。

if (awin && !awin.closed) {
    awin.close();
}
if (bwin && !bwin.closed) {
    bwin.close();
}

尝试此测试后,在致电awin = window.open(后记下awin变量的值,并在关闭弹出式重新检查时awin值仍然相同。