弹出窗口没有从父窗口关闭

PopUp not closing from parent

本文关键字:窗口      更新时间:2023-09-26

我有一个问题,关闭一个弹出窗口。我的问题是独一无二的,如果我从父窗口单击登出,它会关闭所有窗口,但是当我从子窗口登出时,我将从父窗口登出,因此它不会关闭打开的其他子窗口。

当我从一个孩子注销,然后我从一个父母注销,我检查在控制台,它不进入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条件

此代码仅在win和bwin对弹出框有有效引用时才会执行。

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

尝试这个测试,在您调用awin = window.open(后写下awin变量的值,并在关闭弹出窗口时重新检查awin值是否仍然相同。