Is there a way in javascript to get names or count all open browser windows?

I guess the answer is no, but I'm just wondering if anyone has any ideas.

0


source to share


1 answer


This was done on purpose for security reasons. So you are mostly right, there is no easy way.

However, if you are using a web application that opens windows, the "main" window may contain a list of grips for opening windows. You can initialize an array like this:

var openWindows = [];

      



and then enter a method to open a window that looks like this:

function openWindow(url, ... etc)
{
    var w = window.open(url, ... etc);
    openWindows[openWindows.length] = w;
}

      

Assuming you used this method to open all other windows, and assuming you can go into the collection (if the main window navigates to a different page, the array will be lost), you will have a list of windows. You can find out how many are still open by iterating through the array and checking the "window.closed" property.

+2


source







All Articles