所以我正在开发一个 Firefox 插件,它可以向任何网页的 DOM 添加一些 HTML。
这里的想法是我使用一个名为template.html
作为模板,位于data
addon 文件夹内的文件夹。
接下来,我想使用该内容template.html
文件放在一个变量中,这样我就可以将它附加到 DOM 中。
myAddon/data/template.html:
<div>{{test}}</div>
myAddon/lib/main.js:
var template = ... // This is where I want to fetch the contents of template.html.
pageMod.PageMod({
include: "*", // Apply script at any page
contentScriptFile: [data.url("jquery-1.11.2.min.js"), data.url("main.js")], // Include jQuery and myAddon/data/main.js
onAttach: function(worker){ // when these files are attached, send the content of the html-file to the script.
worker.port.emit("sendTemplate", template);
}
});
myAddon/data/main.js
self.port.on("sendTemplate", function(template){
// var template should be <div>{{test}}</div>
}
我在 SDK 中找到了“Panel”,但我不想将 HTML 文件显示为面板。
其次,我尝试只发送 template.html 的资源 URL,然后发送到$.get(templateURL)
in myAddon/data/main.js
,但这不起作用,因为 Firefox 不允许resource://
- 文件为$.get()
'd.
如何确保保存到插件数据文件夹中的 HTML 文件的内容作为字符串获取并放入变量中?