我正在编写一个 Firefox 扩展,需要将 css 文件注入(inject)网页。 css 文件与扩展程序捆绑在一起,因此我可以使用 chrome url 访问它
chrome://extensionid/content/skin/style.css
我试图在页面加载时像这样注入(inject)CSS:
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);
但是,当我检查我创建的 link
元素时,CSS 未加载,Firebug 显示“已过滤的 chrome url”消息而不是文件内容。如果我尝试从外部服务器加载此 css 文件,一切都很好。
有办法加载与扩展捆绑在一起的 css 文件吗?
最佳答案
使用resource:
而不是 chrome:
?
关于firefox - Firefox 扩展如何将本地 css 文件注入(inject)网页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2731736/