简体   繁体   中英

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. 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. Am I correct? And the firefox API is called Jetpack or I am totally at the wrong place?

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.

For example, in you main XUL document, you'd add links to javascript containing your logic / callbacks like this:

<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:

<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..

A plugin is basically a zip file with a different name. You'll build your javascript and include it in the zipped plugin file. It's copied to the firefox directories when it's installed. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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