开发者

Checkbox in firefox extension

I want to place a menu item for my extension that has a check.

<menupopup id="menu_ToolsPopup">
    <menuitem type="checkbox" label="Convert" id="menu_ToolsPopupItem"/>    
</menupopup>

overlay.js

window.addEventListener("load", function() {myExtension.init()}, false);
init: function() {          
      window.addEventListener("copy", function() {myExtension.Test()}, false);       
 },

  Test: function (win) {    
    var x= document.getElementById("menu_ToolsPopupItem"); //not null!!! alert(x)=> [object XULElement]
    alert(x.checked);//-> undefined
}

I don't get the state of the menu item.

and also how do I save the selection after I restart the browser? 开发者_如何学运维


Looks like you have to access the attribute -- there's no convenient property wrapper in this case:

[attribute] checked
    Type: boolean 
    Indicates whether the element is checked or not. 
    Use hasAttribute() to determine whether this attribute is set instead of getAttribute().

https://developer.mozilla.org/en/XUL/menuitem#a-checked


and also how do I save the selection after I restart the browser?

There are quite possibly a few different ways. The first one that comes to mind is to store it in a preference. https://developer.mozilla.org/en/Code_snippets/Preferences


Historically the reason menuitems generally don't have property wrappers for attributes is that there were some cases that they didn't work. I don't know whether that's still true.

To persist the checked attribute of a menuitem across a restart the easiest way is to add the persist="checked" attribute.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜