Persisting elements in XUL

An obivious answer to a simple problem I encountered when developing a firefox extension.

The problem

In my Browseamp Remote Control firefox extension I have a menu popup containing some checkbox items. I use these checkbox items to show or hide certain buttons on the toolbar.

The view state should be remembered between browser sessions so I used the persist attribute to make this happen. Unfortunatly this didn’t work. Every time I restarted the browser the checkboxes would return to there default state. Luckily after some digging through some different code examples I found the obvious solution.

The solution

The answer is quite simple. Firefox only remembers the state of attribute values when the element has an ID attribute. In my case I forgot to ad the ID so persist didn’t work. I hope this helps someone struggling with similar problems.

Categorieën: Firefox XUL