这是我想要做的:
var mainPanel = require("panel").Panel({
width: '200',
height: '500',
contentURL: gatewayURL,
contentScriptWhen: "start",
contentScriptFile: [
self.data.url("messagelistener.js")
]
});
var button = toolbar.ToolbarButton({
'id': 'com.user043.myOneButton',
'image': require("self").data.url("image-24.ico"),
'label': "Test",
'panel': mainPanel
});
tabs.on('ready', function(tab) {
if(tab.url==="http://www.google.com") {
mainPanel.show(); //This opens panel in centre. I want the panel to be anchored to the button it is associated to(just like it appears when I click on toolbarbutton). How do I get the DOM of the button created by ToolbarButton API?
}
}
我正在使用erik-vold的toolbarbutton API:https://github.com/voldsoftware/toolbarbutton-jplib。
如何获取按钮的DOM以便我可以执行mainPanel.show(tbb);
之类的操作,其中tbb =按钮的DOM?请帮忙!
答案 0 :(得分:0)
panel.show(require('sdk/window/utils').getMostRecentBrowserWindow().document.getElementById('com.user043.myOneButton'))
答案 1 :(得分:0)
var mainPanel = require("panel").Panel({
width: '200',
height: '500',
contentURL: gatewayURL,
contentScriptWhen: "start",
contentScriptFile: [
self.data.url("messagelistener.js")
]
});
var button = toolbar.ToolbarButton({
'id': 'com.user043.myOneButton',
'image': require("self").data.url("image-24.ico"),
'label': "Test",
onClick: function(view) {
view.panel = mainPanel;
}
});
Instead of using mainPanel.show(), use view.panel = mainPanel;. It will solve the problem bcz I did the same and it works for me.