Firefox addon 将当前选项卡URL传送到弹出窗口
我尝试了以下有关StackOverflow的代码教程,但未能在弹出窗口中实际接收活动选项卡URLFirefox addon 将当前选项卡URL传送到弹出窗口,firefox-addon,crossrider,Firefox Addon,Crossrider,我尝试了以下有关StackOverflow的代码教程,但未能在弹出窗口中实际接收活动选项卡URL http://stackoverflow.com/questions/21043684/sending-data-from-popup-to-extension-js-not-working http://stackoverflow.com/questions/21017681/how-to-send-data-from-popup-script-to-background-js-in-crossr
http://stackoverflow.com/questions/21043684/sending-data-from-popup-to-extension-js-not-working
http://stackoverflow.com/questions/21017681/how-to-send-data-from-popup-script-to-background-js-in-crossrider
我的目标是在弹出窗口中接收活动选项卡URL,只要用户在该选项卡上。这个URL是对需要从数据库中获取的数据的引用,因此对于我的插件来说是必不可少的
如果能提供一个有效的例子,我将不胜感激
编辑
我现在可以在弹出窗口中获取URL,当选项卡更改或URL更改时,会显示网站的URL。但是,这对我来说没有用处,因为用户单击弹出窗口后我就需要URL,这样我就可以获取活动选项卡的URL,并对本地数据库运行查询以获取其中的数据我该怎么做?
谢谢 我不知道如何在SDK中实现它 但您要做的是添加一个TabSelect事件侦听器 这是如何在引导或覆盖插件中完成的
function exampleTabSelected(event) {
//tab was selected
var tab = event.target; //this tab is the actual thingy you click in the tab bar at top
var tabBrowser = tab.linkedBrowser; //this is the chrome browser within this tab
var tabContentWindow = tabBrowser.contentWindow; //this is the HTML (or whatever type) contained inside the tab, this is where your website is
var siteLocationObj = tabContentWindow.location;
//location now includes properties like href, host, pathname, hash, and port
//now put your the id of your id of the panel and you can do whatever to it
var chromeWindow = tab.ownerGlobal; //this is the firefox browser window that the tab is in
chromeWindow.document.getElementById('YOUR-PANEL-ID-HERE').querySelector('iframe').contentDocument.innerHTML = 'you are now on page: ' siteLocationObj.href;
}
// During initialisation
var container = gBrowser.tabContainer;
container.addEventListener("TabSelect", exampleTabSelected, false);
// When no longer needed
//container.removeEventListener("TabSelect", exampleTabSelected, false);
@通常,在弹出范围内,您无法直接确定选项卡何时变为活动状态。但是,在后台范围中,您可以使用Crossrider方法获取活动选项卡信息,然后使用将信息发送到弹出窗口 实现这一点的代码如下所示: background.js:
appAPI.ready(function($) {
// Get the Active Tab information
appAPI.tabs.onTabSelectionChanged(function(tabInfo) {
// Send it to the popup
appAPI.tabs.toPopup({tabInfo: tabInfo});
});
});
function crossriderMain($) {
appAPI.message.addListener(function(msg) {
// Do something with the tab URL
console.log('ActiveTab URL is ' + msg.tabInfo.tabUrl);
});
}
popup.html中的crossriderMain:
appAPI.ready(function($) {
// Get the Active Tab information
appAPI.tabs.onTabSelectionChanged(function(tabInfo) {
// Send it to the popup
appAPI.tabs.toPopup({tabInfo: tabInfo});
});
});
function crossriderMain($) {
appAPI.message.addListener(function(msg) {
// Do something with the tab URL
console.log('ActiveTab URL is ' + msg.tabInfo.tabUrl);
});
}
[披露:我是一名交叉骑手员工]我不明白。张贴您现在如何获取url的示例代码。您的面板小部件。邮政编码,这对你有好处。