简体   繁体   English

Firefox插件:其他文件中的访问变量

[英]Firefox Addon: Access Variable in other File

How can i easy access the variable "test" from main.js? 我如何从main.js轻松访问变量“ test”?

    \my-addon-project
       \data 
         \file.js (var test = "123")
       \lib: 
         \main.js

The main question is, how to include the file.js in the main.js. 主要问题是,如何在main.js中包含file.js。 And how do i get the value of the variable "test". 以及如何获取变量“ test”的值。

With require? 与要求? Searched a few hours for this simple question. 在几个小时内搜索了这个简单的问题。

Please help me. 请帮我。 Thx. 谢谢。

ok make a jsm file, its real simple, here is an example how to make one called hello world: 好的,制作一个jsm文件,实际上非常简单,这是一个如何制作一个名为hello world的示例:

see the comments bellow the gist it tells you how to access this jsm in another addon, for example purposes it shows how to do it in scratchpad. 请参阅下面的注释,它告诉您如何在另一个插件中访问此jsm,例如,它说明了如何在暂存器中执行此操作。

https://gist.github.com/Noitidart/9045387 https://gist.github.com/Noitidart/9045387

Looks like you're using the add-on sdk. 看起来您正在使用附加SDK。 Here's how to communicate between main.js and content scripts . 这是main.js和内容脚本之间进行通信的方法

All the resources you'll ever need can be found in the docs . 您需要的所有资源都可以在docs中找到。 So you should only be searching if what you read there is confusing or incomplete. 因此,您应该仅在阅读的内容令人困惑或不完整时进行搜索。

Add a comment if you have questions about how to navigate the docs. 如果您对如何浏览文档有疑问,请添加评论。

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

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