简体   繁体   中英

Close all the child window from Parent window

I want to open a Report Page such that from Login it should go to a Main Page which will itself open in a new window. On Main Page, there are two buttons. Clicking on any button it will open a particular report associated with that button in new window.

Now, the problem is there is a link on each Report Page which should go back to Main Page (ie It should minimise the report page). Also, if a user opens a second report again it will open in new window and hit the link to Main Page it should also minimise second report window.

Also, there is a logout on the 3 pages ie On Main Page, First Report and Second Report. So clicking on Logout from Main Page should close the all minimised window if there any. On clicking Logout from any other page ie other reports it should invalidate the session.

So the flow would be- 流

My problem is I am not able to close second child window when Logout is called from first. Also, if logout is called from Main page how to close all pop-up window.

Code that I am using to open Main Page from Login -

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);
    }

Code to open Report from Main Page -

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);
}

Same code I am using to open Report 2 just I am using different URL.

On clicking logout from child I am calling this function -

function logout()
    {


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

Same logout function is used second child

Logout function for main page -

function onLogout(){

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

When open a window with:

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

that window can access his opener with:

window.opener

Then, in each child window you can control his behaviour with is own window object, and call parent methods or properties with window.opener .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM