开发者

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 开发者_Go百科window.open(....) and opening multiple child windows.


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 function
window.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


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. :-)


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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜