Firefox Addon that reacts on click (left)

China☆狼群 提交于 2019-12-11 19:43:55

问题


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


回答1:


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:

https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/tutorials/index.html#getting-started



来源:https://stackoverflow.com/questions/19980649/firefox-addon-that-reacts-on-click-left

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!