简体   繁体   中英

How to include a script for use anywhere in the Add-on?

In my firefox addon, I have a script called "global.js" that I need to use in several dialogues (xul). Do I need to include the script in each xul file, or is there a better way? I call the same function from each dialogue, and so I need them available to any place in the addon.

Yes you need to include it in each XUL file. If you have multiple files that you need to access you could reference them using JavaScript code modules from the global.js file so you don't have to keep changing multiple XUL files whenever you add a new dependency.

There are other options (like having a single XUL file and a bunch of overlays to modify it for specific purposes) but without knowing anything more about your use case, I'd say you're probably better off just biting the bullet and including that one script file everywhere.

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