Skip to content Skip to sidebar Skip to footer

How To Get The References Of All Already Opened Child Windows

I want to get the references of all already opened child windows. is there any way? I am not using child = window.open(....) just using window.open(....) and opening multiple child

Solution 1:

If you don't want to change your current code, you can simply override window.open() function:

var openedWindows = [];
window._open = window.open; // saving original functionwindow.open = function(url,name,params){
    openedWindows.push(window._open(url,name,params));
    // you can store names also...
}

Run this code before calling window.open(). All the references to the opened windows will be stored in openedWindows array. You can access them anywhere you want

Solution 2:

I don't believe you can, unless you know the windows' names, which I'm guessing you don't. (If you know their names, you can use window.open("", "name") to get a reference to them.)

The better option is, of course, to remember the reference returned from window.open in the first place — but you know that. :-)

Solution 3:

Ok, I used the answers to this question in Oracle CRM onDemand to disable a select in a popup window executing the script from the parent window, and it worked! (I have no control over the generation of popup windows, they are opened by the application framework)

Let's see how I did it:

Context: In a detail page the user can add some info by clicking in a magnifying glass icon >>> a new window opens containing a search form, but a select is disturbing the administrator: If the user change its default value he/she will gain access to forbidden records!! Oh my God!

First Approach: Disable that select now!!

Attempt: I found the image's onclick attrib with my browser's dev tools (F12). There was a openAssocPopup method, and then i knew the name of the child window: 'OccamPopup1' :)

Okay! So let's do some magic (executed at the parent window):

window.open("","OccamPopup1").document.getElementById("frmSearch.AQ").setAttribute("disabled", true);

I think this may help, as this question helped to me too. You were right. Now i'm trying to wrap the child's document object within the parent's jQuery object so i can gain access to the entire child's DOM... but this is another story...

Solution 4:

You would be best to name the windows using a prefix and a counter.

I needed to detect if a named window (i.e. CBCheckout) was already open and used this:

var signupWindow = window.open('','CBCheckout','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=1,height=1');
try {
    if (signupWindow.document.location.href == "about:blank") {
        signupWindow.close();
        signupWindow = undefined;
    }
} catch (e) { }

This recaptured the reference to the named open window. If it didn't exist, you'd see a small window popup for a second.

If you know the possible names of the windows, you can cycle through the names, attempting to locate them.

Post a Comment for "How To Get The References Of All Already Opened Child Windows"