所以我正在开发一个Firefox插件,可以在任何网页的DOM中添加一些HTML.
这里的想法是我使用一个名为template.html模板的文件,它位于dataaddon文件夹内的文件夹中.接下来,我想template.html在变量中使用该文件的内容,以便我可以将它附加到DOM.
myAddon /数据/ template.html:
<div>{{test}}</div>
Run Code Online (Sandbox Code Playgroud)
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);
}
});
Run Code Online (Sandbox Code Playgroud)
myAddon /数据/ main.js
self.port.on("sendTemplate", function(template){
// var template should be <div>{{test}}</div>
} …Run Code Online (Sandbox Code Playgroud)