查找当前标签的网址。制作一个FireFox浏览器插件 [英] Find URL of current tab. Making a FireFox Browser add-on
问题描述
我正在制作Firefox浏览器插件,需要找到当前标签的网址。
我试过这个帖子在当前选项卡/窗口中打开一个URL 但它告诉我'窗口'没有被定义。 (我认为是因为我正在做一个附加组件,而不是一个扩展组件)。
这是我试过的:
var widgets = require('widget');
var tabs = require('tabs');
var widget1 = widgets.Widget({
id:widget1,
label:widget1,
contentURL:http://www.mozilla .org / favicon,
onClick:function(){
console.log(tabs.url);
}
})
我做了一个小部件,当我点击它时,当前选项卡的url应该是'console.log'ed。
似乎没有发生!继续收到info:undefined,这意味着tabs.url没有返回任何东西。但是这似乎是根据 https://addons.mozilla.org/zh-CN/developers/docs/sdk/1.5/packages/addon-kit/docs/tabs.html
任何人有任何想法?
谢谢,
$ c> const {ActionButton} = require(sdk / ui / button / action);
const clipboard = require(sdk / clipboard);
const tabs = require('sdk / tabs');
let button = ActionButton({
id:my-button-id,
label:Button Label,
icon:{
32:chrome://mozapps/skin/extensions/extensionGeneric.png
},
onClick:function(state){
let url = tabs.activeTab.url;
console.log(active tab url:,url);
require(sdk / notifications)。notify({
title:Active Tab's Url is+ url,
text:Click to copy。,
onClick:function(){
clipboard.set(url);
}
});
}
});
您应该查看选项卡模块上的文档
注意:我已经更新此代码示例使用自Firefox 29以来的新UI模块 - 原始问题中使用的小部件模块在当时有效,但此后已被弃用,然后被移除。
I'm making a Firefox Browser Add-on and need to find the url of the current tab
I've tried this post Opening a URL in current tab/window from a Firefox Extension but it tells me that 'window' is not defined. (I think because I am making an add-on rather than an extension.)
Here's what I've tried to do:
var widgets = require('widget');
var tabs = require('tabs');
var widget1 = widgets.Widget({
id: "widget1",
label: "widget1",
contentURL: "http://www.mozilla.org/favicon",
onClick: function() {
console.log(tabs.url);
}
})
I've made a widget such that when I click it the url of the current tab should be 'console.log'ed.
Doesn't seem to happen! Keep getting "info: undefined" which clearly means that tabs.url isn't returning anything. But this seems to be the way to use it according to https://addons.mozilla.org/en-US/developers/docs/sdk/1.5/packages/addon-kit/docs/tabs.html
Anyone have any ideas?
Thanks,
Will
You're almost there:
const { ActionButton } = require("sdk/ui/button/action");
const clipboard = require("sdk/clipboard");
const tabs = require('sdk/tabs');
let button = ActionButton({
id: "my-button-id",
label: "Button Label",
icon: {
"32": "chrome://mozapps/skin/extensions/extensionGeneric.png"
},
onClick: function(state) {
let url = tabs.activeTab.url;
console.log("active tab url:", url);
require("sdk/notifications").notify({
title: "Active Tab's Url is "+url,
text: "Click to copy.",
onClick: function() {
clipboard.set(url);
}
});
}
});
You should check out the documentation on the tabs module.
Note: I've updated this code example to use the new ui modules available since Firefox 29 - the 'widget' module used in the original question was valid at the time but has since been deprecated and then removed.
这篇关于查找当前标签的网址。制作一个FireFox浏览器插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!