Вопрос

I am building an extension in Firefox and I wonder if there is a way to know when opening a browser how many instances are open using javascript?

For example I open one instance of Firefox browser I want to get the number of the current instances.

Any ideas?

Это было полезно?

Решение

Found something that may help you:

nsIWindowMediator is a component that keeps track of open windows. It has getEnumerator method that allows you to get all open windows.

If you loop through it, and count them, you get the number of open windows, like so:

var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
    .getService(Components.interfaces.nsIWindowMediator);

var enumerator = windowMediator.getEnumerator(null);
var count = 0;
while (enumerator.hasMoreElements()) {
    var myWindow = enumerator.getNext();
    count++;
}
alert(count);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top