문제

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