How to get the references of all already opened child windows

Govind Malviya picture Govind Malviya · Jun 14, 2011 · Viewed 43.4k times · Source

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

Answer

Hrant Khachatrian picture Hrant Khachatrian · Jun 14, 2011

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