I am just started to create firefox add on. My first try was to capture the users left click event and display an alert. but this isn't working:
window.addEventListener("click", function(e) {
alert("blub");
}, false);
i also tried it wit "gBrowser". At the end i want to analyze the target element and if it matches some criteria i want to open a new tab with a link generated from data from the target tag. for nearly all parts i found code snippets but first i need the simple click handling. besides this is there any syntax checking debugging tool. i am using Add-on Builder - i f i click on "test" for the code abov it says "add-on installed" but iam unsure if it's syntactically correct.
thx in advance
That won't work, mainly because your main.js does not have direct access to the window. This code example adds a click event listener to all open tabs:
require('sdk/page-mod').PageMod({
include: ["*"],
contentScript: 'window.addEventListener("click", function(e) { alert("blub"); }, false);',
attachTo: ["existing", "top"]
});
I really recommend you look at the documentation for the add-on SDK to get started, there are some basic concepts you should learn so you don't get frustrated: