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