简体   繁体   English

向Firefox扩展添加功能

[英]Add functionality to firefox extension

I am trying to make my first steps with Firefox addon programming but I am confused in one point.I have read the "how to build a hello world addon" tutorials but I can't figure out how to add complex/advanced behavior, let's say with JavaScript. 我正在尝试进行Firefox插件编程的第一步,但是我很困惑。我已经阅读了“如何构建hello world插件”教程,但是我不知道如何添加复杂/高级行为,让我们用JavaScript说。 I think I have to write the JavaScript code, as I had to "put" it inside my webpage, and make a link from a xul file to the js file. 我认为我必须编写JavaScript代码,因为我必须将其“放入”网页中,并建立从xul文件到js文件的链接。 Am I correct? 我对么? And the firefox API is called Jetpack or I am totally at the wrong place? firefox API被称为Jetpack还是我完全在错误的地方?

You can actually add event-handling to your XUL elements in a way very similar to how you'd do it in ordinary Web pages. 实际上,您可以将事件处理添加到XUL元素中,方式与在普通Web页面中执行事件处理的方式非常相似。

For example, in you main XUL document, you'd add links to javascript containing your logic / callbacks like this: 例如,在您的主要XUL文档中,您将向javascript添加包含如下逻辑/回调的链接:

<script src="findfile.js"/>
<script src="chrome://findfiles/content/help.js"/>
<script src="http://www.example.com/js/items.js"/>

And assuming you have a button in your XUL (your addon somewhere), then you can make it call javascript when some event happens like this: 并假设您在XUL(您的插件在某处)中有一个按钮,那么可以在发生以下事件时使其调用javascript:

<button label="OK" oncommand="doMyAction();"/>

or something like: 或类似的东西:

<button label="OK" oncommand="alert('Button was pressed!');"/>

Check this Mozilla Documentation for more insights into this.. 查看此Mozilla文档,以获取有关此内容的更多信息。

A plugin is basically a zip file with a different name. 插件基本上是一个具有不同名称的zip文件。 You'll build your javascript and include it in the zipped plugin file. 您将构建JavaScript,并将其包含在压缩的插件文件中。 It's copied to the firefox directories when it's installed. 安装后将其复制到firefox目录。 Building one of these isn't trivial and requires a good knowledge of the working of javascript and the browser... or a lot of patience. 构建其中之一并不是一件容易的事,需要对javascript和浏览器的工作有充分的了解...或者要有很多耐心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM