我有一个CustomizableUI.jsm按钮,我添加到工具栏。点击此按钮会打开一个加载了chrome页面的面板。
我希望所有窗口都打开同一个面板。所以我的想法是将面板添加到Services.appShell.hiddenDOMWindow
然后打开它锚定到CustomizableUI.jsm按钮。
但是我在将面板添加到hidddenDOMWindow时遇到了问题。
如果您将第一行设为var win = window
,则此代码可以从暂存器中正常工作。但是,如果你将它设为var win = Services.appShell.hiddenDOMWindow
,则将面板附加到弹出窗口会有问题。太奇怪了。
这里的代码是appShell隐藏窗口代码。如果你成功var win= window
它可以正常工作:
var win = window; //Services.appShell.hiddenDOMWindow;
var panel = win.document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul','panel');
var props = {
type: 'arrow',
style: 'width:300px;height:100px;'
}
for (var p in props) {
panel.setAttribute(p, props[p]);
}
var popupset = win.document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul','popupset');
popupset.appendChild(panel);
win.document.documentElement.appendChild(popupset);
panel.addEventListener('popuphiding', function (e) {
e.preventDefault();
e.stopPropagation();
//panel.removeEventListener('popuphiding', arguments.callee, false); //if dont have this then cant do hidepopup after animation as hiding will be prevented
panel.addEventListener('transitionend', function () {
panel.hidePopup(); //just hide it, if want this then comment out line 19 also uncomment line 16
//panel.parentNode.removeChild(panel); //remove it from dom //if want this then comment out line 18
}, false);
panel.ownerDocument.getAnonymousNodes(panel)[0].setAttribute('style', 'transform:translate(0,-50px);opacity:0.9;transition: transform 0.2s ease-in, opacity 0.15s ease-in');
}, false);
panel.openPopup(window.document.documentElement, 'overlap', 100, 100);