无法使用 firefox 扩展将本地 css 文件注入网页
我阅读了线程:
inserting-css-with-a-firefox-extension
<一href="https://stackoverflow.com/questions/8147552/inserting-local-css-file-with-firefox-extension">inserting-local-css-file-with-firefox-extension
我确实这么做了如:
how-can-a-firefox- Extension-inject-a-local-css-file-into-a-webpage
但我仍然无法将本地 css 文件注入到网页中。
我的js代码是:
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);
当我在浏览器的位置栏中输入“chrome://myExtension/skin/sty.css”时,我可以看到我的css文件,这非常简单:
* {color:red !important;}
但由于某种原因,页面中的文本没有变红。
我查看了网页中的 firebug,在 head 标签中看到了这样的内容:
+ <link rel="stylesheet" type="text/css" href="resource://myExtension/skin/sty.css">
但是按“+”号并没有打开 css 文件内容。
我缺少什么?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用样式表服务
You can use Stylesheet Service