Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 936
Govind Malviya Avatar asked Jun 14 '11 07:06

Govind Malviya


People also ask

How to get the popup window name in JavaScript?

The syntax to open a popup is: window. open(url, name, params) : url.

How do you find the parent element in a child window?

You just need to prefix “ window. opener. ” and write the same code that you will write in the parent window's HTML page to access its elements.

How do I transfer data from child window to parent window?

From a child window or a small window once opened, we can transfer any user entered value to main or parent window by using JavaScript. You can see the demo of this here. Here the parent window is known as opener. So the value we enter in a child window we can pass to main by using opener.

How do I close all kids windows?

If you open all child windows with window. open, include this javascript in all pages, then CloseAll(false); from any included page will close all child, grandchildren, great-grand... etc., and redirect the first (root) page to login.


2 Answers

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

like image 174
Hrant Khachatrian Avatar answered Sep 24 '22 09:09

Hrant Khachatrian


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

like image 34
T.J. Crowder Avatar answered Sep 22 '22 09:09

T.J. Crowder