Hi,
ive been trying to learn to code a firefox addon and came across this code, It will open the link into a new tab from a panel. But how can I change the code so it work from links from main window not in the panel. Ive been trying without luck, please help
cheers
//index.js
var data = require(“sdk/self”).data;
var button = require(“sdk/ui/button/action”).ActionButton({
id: “reddit-panel”,
label: “Reddit Panel”,
icon: “./icon-16.png”,
onClick: function() {
reddit_panel.show();
}
});
var reddit_panel = require(“sdk/panel”).Panel({
width: 240,
height: 320,
contentURL: “http://www.reddit.com/.mobile?keep_extension=True”,
contentScriptFile: [data.url(“jquery-2.1.0.min.js”),
data.url(“panel.js”)]
});
reddit_panel.port.on(“click”, function(url) {
require(“sdk/tabs”).open(url);
});
$(window).click(function (event) {
var t = event.target;
// Don’t intercept the click if it isn’t on a link.
if (t.nodeName != “A”)
return;
// Don’t intercept the click if it was on one of the links in the header
// or next/previous footer, since those links should load in the panel itself.
if ($(t).parents(’#header’).length || $(t).parents(’.nextprev’).length)
return;
// Intercept the click, passing it to the addon, which will load it in a tab.
event.stopPropagation();
event.preventDefault();
self.port.emit(‘click’, t.toString());
});