单击左侧的Firefox Addon(左侧) [英] Firefox Addon that reacts on click (left)

查看:139
本文介绍了单击左侧的Firefox Addon(左侧)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始创建Firefox添加。我的第一个尝试是捕捉用户左键单击事件并显示警报。但这是行不通的:
$ b $ pre $ window.addEventListener(click,函数(e){

alert(blub);
},false);

我也尝试过使用gBrowser。最后,我想分析目标元素,如果它符合一些标准,我想打开一个新的标签与从目标标记的数据生成的链接。
几乎所有的部分,我发现代码片段,但首先我需要简单的点击处理。除此之外,还有任何语法检查调试工具。我使用插件生成器 - ifi点击测试的代码abov它说附加安装,但我不确定它是否在语法上是正确的。



thx提前

解决方案

那不行,主要是因为你的main.js没有直接访问窗口。这个代码示例将一个点击事件监听器添加到所有打开的选项卡:
$ b

  require('sdk / page-mod')。PageMod {
include:[*],
contentScript:'window.addEventListener(click,function(e){alert(blub);},false);',
attachTo:[existing,top]
});

我真的建议您查看附加SDK的文档来开始,基本的概念,你应该学习,所以你不会感到沮丧:

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


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:

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

这篇关于单击左侧的Firefox Addon(左侧)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆