Pee*_*Haa 7 javascript firefox-addon firefox-addon-sdk
我正在开发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);
}
Run Code Online (Sandbox Code Playgroud)
该文件位于我的数据目录中.如何在firefox扩展内容脚本(我用于chrome.extension.getURL()Chrome)中引用js文件?
can*_*ani 10
如果您在基于SDK的插件中使用main.js,则需要并使用"self"对象中的"data"帮助器:
var data = require('self').data;
console.log(data.url('somefile.js')); // prints the resource uri to the file.
Run Code Online (Sandbox Code Playgroud)
欲了解更多信息:
https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/self#data
获得此资源后,您可以使用self.postMessage或self.port.emit将其提供给内容脚本:
https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts
| 归档时间: |
|
| 查看次数: |
2272 次 |
| 最近记录: |