我正在编写一个为网站添加功能的插件。 但我需要解析.js之间的变量
main.js:
pageMod.PageMod({
include: ["*"],
contentScriptWhen: 'end',
contentScriptFile: data.url("MyContent.js"),
contentScriptOptions: {
showOptions: true,
dataUrl: data.url("MyContent.js") // To parse the URL-Path
}
});
MyContent.js:
//to read the URL like resource://.....:
var dataUrl=self.options.dataUrl.substring(0,self.options.dataUrl.lastIndexOf("/")+1)
var script = document.createElement("script");
script.type = "text/javascript";
script.src = dataUrl+"scripts.js";
window.document.head.appendChild(script);
变量dataUrl存在于MyContent.js中,但不存在于MyScripts.js中 我需要MyScripts.js中的变量dataUrl来知道保存在data-folder中的一些图像的url。 如何定义可从所有脚本访问的全局变量? 与工作者可以在main.js和MyContent.js之间进行通信,但不能与MyScripts.js进行通信