【问题标题】:Close all the child window from Parent window从父窗口关闭所有子窗口
【发布时间】:2017-02-08 19:34:44
【问题描述】:

我想打开一个报告页面,以便从登录它应该转到一个主页,该主页本身将在一个新窗口中打开。在主页上,有两个按钮。单击任何按钮,它将在新窗口中打开与该按钮关联的特定报告。

现在,问题是每个报告页面上都有一个链接应该返回到主页(即它应该最小化报告页面)。此外,如果用户再次打开第二个报告,它将在新窗口中打开并点击到主页的链接,它还应该最小化第二个报告窗口。

此外,在主页、第一份报告和第二份报告这 3 个页面上都有注销。因此,从主页单击注销应该关闭所有最小化的窗口(如果有)。从任何其他页面(即其他报告)单击注销时,它应该使会话无效。

所以流程将是-

我的问题是从第一次调用注销时我无法关闭第二个子窗口。此外,如果从主页调用注销,如何关闭所有弹出窗口。

我用来从登录打开主页的代码 -

function RedirectPage(path)
    {


      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.

                   + "";  

        var win = window.open(path,'_blank',strWinProp);
        self.setTimeout("closeMe()",500);
    }

从主页打开报告的代码 -

function report1() {
    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.

                   + "";  
    window.open(Url + userName + "&requestID=" + sessionId + "&userId="
            + userId + "&lValue=" + lvalue + "&lVer=" + lver,'_blank',strWinProp);
}

我用于打开报告 2 的代码相同,只是我使用了不同的 URL。

点击从子节点注销时,我正在调用此函数 -

function logout()
    {


        opener.location.href = '/Login.html';
        close();
    }

第二个孩子使用相同的注销功能

主页退出功能-

function onLogout(){

window.opener.location.reload(true);
window.opener.location.href=loginPageUrl;
window.close(); 
}

【问题讨论】:

标签: javascript html logout window.open window.opener


【解决方案1】:

当打开一个窗口时:

var win = window.open(path,'_blank',strWinProp);

该窗口可以通过以下方式访问他的开启器:

window.opener

然后,在每个子窗口中,您可以使用自己的window 对象控制他的行为,并使用window.opener 调用父方法或属性。

【讨论】:

  • 所以在孩子我必须写 window.opener 然后是父路径?
  • 认为子窗口中的window.opener 是对父窗口中window 的引用。子中的window.opener 与父的window 具有完全相同的方法和属性,两者都是相同的“窗口”。
  • 当我有两个弹出窗口时出现问题,所以在注销时我无法同时关闭这两个弹出窗口。只有调用注销的一个被关闭...有没有其他方法可以做到这一点?
猜你喜欢
  • 1970-01-01
  • 2013-02-14
  • 1970-01-01
  • 2020-10-17
  • 2023-03-07
  • 1970-01-01
  • 2012-12-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多