我正在开发一个 Firefox 扩展,我需要将 JavaScript 从内容脚本注入到页面中。在我的 Chrome 扩展中,我做了以下操作:
this.initializeJplayerSupport = function() {
var script = document.createElement('script');
script.setAttribute('type', 'application/javascript');
script.setAttribute('src', chrome.extension.getURL('js/custom-jplayer.js'));
document.head.appendChild(script);
}
该文件位于我的数据目录中。如何在 firefox 扩展内容脚本中引用 js 文件(我在其中使用过chrome.extension.getURL()
对于 Chrome)?
如果您位于基于 SDK 的附加组件的 main.js 中,则需要并使用“self”对象中的“data”助手:
var data = require('self').data;
console.log(data.url('somefile.js')); // prints the resource uri to the file.
欲了解更多信息:
https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/self#data https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/self#data
获取此资源 uri 后,您可以使用 self.postMessage 或 self.port.emit 将其提供给内容脚本:
https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)