1
votes

I read the threads:

inserting-css-with-a-firefox-extension

inserting-local-css-file-with-firefox-extension

I did exacly as in:

how-can-a-firefox-extension-inject-a-local-css-file-into-a-webpage

but still I can't inject a local css file into the webpage.

my js code is:

    var fileref = gBrowser.contentDocument.createElement("link");
    fileref.setAttribute("rel", "stylesheet");
    fileref.setAttribute("type", "text/css");
    fileref.setAttribute("href", "resource://myExtension/skin/sty.css");
    gBrowser.contentDocument.getElementsByTagName("head")[0].appendChild(fileref);

when I'm typing "chrome://myExtension/skin/sty.css" in the location bar in my browser I can see my css file which is quite simple:

* {color:red !important;}

but for some reason the text in the page is not turning red.

I have looked in firebug in the webpage and I saw in the head tag this:

+ <link rel="stylesheet" type="text/css" href="resource://myExtension/skin/sty.css">

but pressing on the '+' sign is not opening the css file content.

What am I missing?

Thanks!

1

1 Answers

0
votes

You can use Stylesheet Service

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 u = ios.newURI("chrome://myExtension/skin/sty.css", null, null);
if(sss.sheetRegistered(u, sss.USER_SHEET))
  sss.unregisterSheet(u, sss.USER_SHEET);