相关疑难解决方法(0)

使用firefox扩展插入本地css文件

我正在构建一个firefox扩展,需要在doc中插入一些元素和css.

我尝试过关注Firefox扩展如何将本地css文件注入网页?使用Firefox扩展插入CSS,但没有运气.

我知道我错过了一些愚蠢的观点,但我无法弄清楚它是什么,如果有人可以指出我,我会非常感激.

继承人我的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/
Run Code Online (Sandbox Code Playgroud)

和我的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);
Run Code Online (Sandbox Code Playgroud)

我甚至在我的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);
Run Code Online (Sandbox Code Playgroud)

再没有运气.

我错过了什么?我真的想不通.


  • 尝试使用控制台,什么也没显示
  • 当我复制并粘贴我的href"chrome://helloworld/skin/global.css"时,我可以在浏览器中看到我的css文件.

javascript css firefox firefox-addon

11
推荐指数
1
解决办法
2007
查看次数

使用Firefox扩展插入CSS

我正在构建一个Firefox扩展,将HTML元素添加到网站的某些页面.我想让它插入一个自定义CSS文件来设置这些元素的样式.如果我在页面上插入带有CSS的标签,它就可以工作,但这不是一个理想的解决方案.

反正有没有让它加载和解析一个CSS文件,好像我在标题中使用了标签,或者我不知何故插入它?

javascript css firefox-addon

8
推荐指数
1
解决办法
5126
查看次数

标签 统计

css ×2

firefox-addon ×2

javascript ×2

firefox ×1