我正在构建一个 Firefox 扩展,需要在文档中插入一些元素和 css。
我尝试以下Firefox 扩展如何将本地 css 文件注入网页? https://stackoverflow.com/questions/2731736/how-can-a-firefox-extension-inject-a-local-css-file-into-a-webpage and 使用 Firefox 扩展插入 CSS https://stackoverflow.com/questions/2685243/inserting-css-with-a-firefox-extension,但没有运气。
我知道我错过了一些愚蠢的观点,但我无法真正弄清楚它是什么,如果有人能向我指出它,我将非常感激。
这是我的 chrome.manifest:
content helloworld content/
overlay chrome://browser/content/browser.xul chrome://helloworld/content/overlay.xul
locale helloworld en-US locale/en-US/
skin helloworld classic/1.0 skin/
还有我的overlay.js:
var fileref = gBrowser.contentDocument.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", "resource://helloworld/skin/global.css");
gBrowser.contentDocument.getElementsByTagName("head")[0].appendChild(fileref);
我什至在我的overlay.js 中尝试过这个
var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"]
.getService(Components.interfaces.nsIStyleSheetService);
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = ios.newURI(url, null, null);
sss.loadAndRegisterSheet(uri, sss.USER_SHEET);
再次没有运气。
我缺少什么?我真的想不通。
- 尝试使用控制台,没有显示任何内容
- 当我复制并粘贴 href“chrome://helloworld/skin/global.css”时,我可以在浏览器中看到我的 css 文件。