Minimize all the open child windows from the main Parent window

I would like to implement a functionality where, upon logging in, the user is directed to a Main Page that opens in a new window. This Main Page contains two buttons, each of which will open a specific report associated with it in a new window when clicked.

The challenge arises when there needs to be a link on each Report Page that allows the user to return to the Main Page (essentially minimizing the report page). Furthermore, if the user opens a second report and then clicks the link to the Main Page, the second report window should also minimize.

Additionally, there is a logout option available on all three pages - Main Page, First Report, and Second Report. Clicking Logout on the Main Page should close all minimized windows, if any exist. Whereas clicking Logout from any other page, i.e. the reports, should invalidate the session.

The flow should follow this path: https://i.stack.imgur.com/iTYgm.png

My current issue lies in the inability to close the second child window when Logout is called from the first one. Also, I am struggling with how to close all pop-up windows if Logout is triggered from the Main page.

Here is the code I am using to open the 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 a Report from the 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);
}

The same code can be used to open Report 2, just with a different URL.

Upon clicking logout from a child page, this function is invoked:

function logout()
    {


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

This same logout function is used for the second child as well.

Logout function for the main page:

function onLogout(){

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

Answer №1

Opening a new window using the following code:

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

allows the newly opened window to access its parent window with the following code:

window.opener

Subsequently, in each child window, you have control over its behavior using its own window object, and can also call parent methods or properties using window.opener.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to modify the bar's color using the .css document

Below is the JavaScript code being used: var marginEducation = {top: 20, right: 30, bottom: 40, left: 300}, widthEducation = 1000, heightEducation = 460; const svgEducation = d3.select("#Education") .append("svg") .attr("w ...

Load texture using ImageUtils with callback in Canvas Renderer

Currently, I am utilizing three.js revision 53. While attempting to load a texture in Canvas Renderer (specifically on Win7) and incorporating a callback for the onLoad event, the texture fails to display. Surprisingly enough, removing the callback functi ...

Eliminating the impact of a CSS selector

I have a complex mark-up structure with multiple CSS classes associated: classA, classB, classC, classD. These classes are used for both styling via CSS and event binding using jQuery selectors. The Challenge: I need the jQuery events to be functional whi ...

How to use JavaScript regular expressions to verify that an input contains more than zero characters

Can someone help me with a simple regex issue? I've tried searching online but couldn't find a suitable example. I'm struggling with regex and just need to ensure that an input contains more than 1 character (i.e. is not blank). My code uses ...

extract non-alphanumeric characters from an array of strings using javascript

I am trying to loop over an array of strings in JavaScript and remove special characters from elements that contain them. I have been successful in achieving this with individual strings, but I am facing some challenges when working with arrays of string ...

Is it possible to successfully pass a parameter from a servlet to a JavaScript function, but encounter issues when trying to view the database

In my view servlet, I am displaying user data from the database in a table. Each row of the table has buttons that allow users to change the cells in that row to text boxes. The issue I am encountering is that when I retrieve the data and loop through to ...

What's preventing me from using the left click function on my published blog post?

This is my first time creating a blogger template and everything seems to be working correctly. However, I have encountered one problem. For some reason, I am unable to left click on my blog post. I have not installed any right/left click disabler and I&a ...

Utilizing onClick to target data within a .map function

I am struggling with the code provided below: const test = (e) => { console.log('example:', e.target.item.attributes.dataIWant); } {records.map((item, index) => { return ( <> <Accordion key={index} ...

What is the best way to change the height of a div element as the user scrolls using JavaScript exclusively?

Coding with JavaScript var changeHeight = () => { let flag = 0; while(flag != 1) { size += 1; return size; } if(size == window.innerHeight/2){ flag == 1; } } var size = 5; document.body.style.height = &qu ...

Is there a way to automatically change the display of an element once the user has closed the menu?

How can I ensure that the display of an element remains unchanged when a user opens and closes my website menu using JavaScript? ...

Utilize the capabilities of the Dropbox Core API in Javascript to effortlessly transfer and store files on

I am currently developing a chrome-extension that has the ability to upload files to the user's Dropbox folder. I have implemented AJAX requests in my code to handle file uploads, and it is working fine for text-based file extensions such as .txt, .js ...

Merging HTML Array with jQuery

I am working with input fields of type text in the following code snippet: <input type="text" minlength="1" maxlength="1" class="myinputs" name="myinputs[]" > <input type="text" minlength="1" maxlength="1" class="myinputs" name="myinputs[]" > ...

Can you explain the mechanics behind the animation of the upvote button on steemit.com?

Behold the upvote button of steemit.com: <span class="Icon chevron-up-circle" style="display: inline-block; width: 1.12rem; height: 1.12rem;"> <svg enable-background="new 0 0 33 33" version="1.1" viewBox="0 0 33 33" xml:space="preserve" xmlns=" ...

Manipulating images live with options for scaling, resizing, and cropping

I am currently developing a content management system that allows users to upload images and attach them to different sections of the pages. My goal is to find a user-friendly, preferably jQuery-based plugin for resizing images before they are cropped. A ...

The ajax function is malfunctioning when called from an external JavaScript file

I am having an issue with a Registration page that only has UserName and Password fields. When I click on the Submit button, I want to be able to submit the new User Details using an ajax call with jQuery. I have tried defining an Insert function on butt ...

Invoking a function within a functional component from a React element

Let's imagine a scenario where we have a Child component that is a functional component and contains a function called a(): export default function child({ ... }) { ... function a() { ... } ... } Now, let's introduce a parent ...

Updating .babelrc to include the paths of JavaScript files for transpilation

Using Babel, I successfully transpiled ES6 JavaScript to ES5 for the project found at I'm currently stuck on updating my .babelrc file in order to automatically transpile a specific ES6 file to a particular ES5 file. Can someone guide me on what cod ...

Objective subject for an element within a :not operation

I have a function that specifically excludes a style on links by targeting their IDs. Each of my links has an ID, so I use that to exclude the style. a:not([id='hopscotch_logo'] { color: red; } Now, I also want to find links that are children o ...

Refreshing a React page will lead to props being empty

The situation I am facing is that the code appears to be correct, but for some reason, when the web page loads, this.props.items does not seem to be passed to Item. Strangely, when I attempt to display this.props.items in console.log, nothing shows up. How ...

wiping out a column in Excel spreadsheets with the help of Node.js or its corresponding node modules

I've attempted various approaches without success. Can you provide guidance on deleting and adding columns within an Excel sheet using Node.js? ...