I'm a beginner with XUL. I have the following problem.
In the browser overlay I declare a menu item which opens a new window - so far so good.
menu_entry.addEventListener('command', function() {
window.open('chrome://myextension/content/mywindow.xul',
'myextension-mywindow',
'chrome,centerscreen');
}, false);
I'd like this to be more flexible. If the window is already open, it should be focused instead. This is what I have tried
menu_entry.addEventListener('command', function() {
let mywindow = document.getElementById('myextension-mywindow');
if (mywindow) {
mywindow.focus();
}
else {
window.open('chrome://myextension/content/mywindow.xul',
'myextension-mywindow',
'chrome,centerscreen');
}
}, false);
The problem is that document.getElementById('myextension-mywindow') always returns null, so I never enter the if. I guess this is because the window is another chrome in itself.
But if this is so, how can I make the windows interact with each other? Is it possible to focus a window from a widget in another window? I cannot do this from a module, since document and window are not available there.