简体   繁体   English

如何在Mozilla FireFox扩展程序中更改自定义工具栏按钮的颜色

[英]How to change color of custom toolbar button in mozilla firefox extension

I have given custom toolbar button (which i have created in overlay.xul) a color in start of javascript then i change its color in script but the problem is that when i opens a new tab the toolbar button color does not resume to its first color or in other words all script work but the color changing line of code does not work which i give in start but it remains myblueclass color. 我在javascript开头给了自定义工具栏按钮(我在overlay.xul中创建的)一种颜色,然后我在脚本中更改了它的颜色,但是问题是当我打开一个新选项卡时,工具栏按钮的颜色不会恢复到它的第一个颜色颜色或换句话说,所有脚本均可工作,但我在开始时给出的颜色更改代码行不起作用,但仍为myblueclass颜色。

window.addEventListener("DOMContentLoaded", function(e) {
    document.getElementById("TutTB-Web-Button").classList.add('myRedClass');

and on certain event in specific web page the following line of code runs. 并在特定网页上的特定事件下运行以下代码行。

document.getElementById("TutTB-Web-Button").classList.add('myblueclass');    

Css code is: CSS代码是:

.myRedClass{
   -moz-appearance: none;
    width: 100px;
    height: 20px;
    margin-bottom:3px;
    margin-left: 90px!important;
    background-color:#FF0000;
    color:#000000;
    font-weight:bold;
    /*border:2px solid #FFFFFF!important;*/
    border-radius: 5px !important;
    /*box-shadow: 5px 5px 5px  #888888!important;*/
        font-family:Arial, Helvetica, sans-serif;

}
.myblueclass{
    -moz-appearance: none;
    width: 100px;
    height: 20px;
    margin-left: 40px;
    background-color:#0000FF;
    color:#FFFFFF;

} 

Have you tried removing the blue class when adding the red one? 添加红色的类别时,您是否尝试过删除蓝色的类别?

window.addEventListener("DOMContentLoaded", function(e) {
    var cList = document.getElementById("TutTB-Web-Button").classList;
    cList.remove('myblueClass');
    cList.add('myRedClass');
}

This can be fixed without using javascript as well. 无需使用JavaScript也可以解决此问题。

Since you want the myRedClass to override myblueclass , you should rearrange your css such that the most important selector appears in the end. 由于您希望myRedClass覆盖myblueclass ,因此应重新排列css,以便最重要的选择器出现在最后。

.myblueclass{
    ...
} 

.myRedClass{
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有Mozilla SDK的Firefox扩展中的带有面板的切换按钮 - Toggle button with panel in Firefox extension with Mozilla SDK 如何使用xul更改在firefox中添加的javascript中工具栏按钮的背景颜色 - How to change background color of toolbar button in javascript which is added in firefox using xul 如何在firefox扩展中更改statusbarpanel背景颜色 - How to change statusbarpanel background color in firefox extension Mozilla Firefox扩展Javascript - Mozilla Firefox Extension Javascript 在Firefox WebExtension中更改SVG工具栏图标的颜色 - Change Color Of SVG toolbar icon in Firefox WebExtension 如何更改 trix 文本编辑器工具栏按钮图标的字体颜色 - How to change font color of button icons for trix text editor toolbar 更改Firefox扩展的工具栏颜色以响应信号 - Changing a Firefox extension's toolbar color in response to signal Mozilla Firefox扩展开发。 577 <100。这怎么可能? - Mozilla Firefox extension developing. 577 < 100. How is this possible? Mozilla(Firefox,Thunderbird)扩展:如何获取扩展ID(来自install.rdf)? - Mozilla (Firefox, Thunderbird) Extension: How to get extension id (from install.rdf)? 在 Mozilla Firefox 扩展中写入文件 - 奇怪的错误 - Writing to file in Mozilla Firefox extension - strange error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM