View auxiliary windows

Using the window.open() function, you can create auxiliary windows and tabs.

How can I get a list of created auxiliary windows and tabs of the "parent" page in JavaScript?

EDIT . I'm looking for a way to do this without tracking the windows I created when I created them.

+4
source share
4 answers

There is no way in javascript to do this. You must track them yourself:

 var windowArray = []; // whenever you open a window... var newWindow = window.open(...); windowArray.push(newWindow); // whenever you close a window... if (opener && !opener.closed && opener.windowArray) { // search for your window in the array var matchingIndex = -1; for (var i = 0; i < opener.windowArray.length; i++) { if (opener.windowArray[i] === window) { matchingIndex = i; break; } } // if your window was found, remove it if (matchingIndex !== -1) { opener.windowArray.splice(matchingIndex, 1); } } 
+4
source

I don't know if there is a built-in way to return child windows and tabs in js, but you can create an array to track them by creating a record in the array every time you call window.open ()

+1
source

I can’t think that you can do this directly, although you can save windows in an array:

 var wins = []; function openWindow(win){ newWin = window.open(win); wins.push(newWin); } 
+1
source

How about this:

 var windowArray = []; windowArray.push(window.open(yourWindow)); 

windowArray will store links to all open windows or tabs.

0
source

All Articles