开发者

How can a Firefox extension inject a local css file into a webpage?

开发者 https://www.devze.com 2022-12-28 06:46 出处:网络
I\'m writing a Firefox extension that needs to inject a css file into开发者_如何学Python webpages. The css file is bundled with the extension, so I can access it using a chrome url

I'm writing a Firefox extension that needs to inject a css file into开发者_如何学Python webpages. The css file is bundled with the extension, so I can access it using a chrome url

chrome://extensionid/content/skin/style.css

I'm trying to inject css like this when the page is loaded:

var fileref = document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", "chrome://extensionid/content/skin/style.css");
document.getElementsByTagName("head")[0].appendChild(fileref);

However, the css isn't loaded and Firebug shows 'Filtered chrome url' message instead of the file content, when I inspect the link element I created. If I try to load this css file from an external server, everything's fine.

Is there are way to load a css file bundled with the extension?


Use resource: instead of chrome:?

0

精彩评论

暂无评论...
验证码 换一张
取 消