javascript - Dynamically show data in the popup which is determined in onpopupshowing event handler -


i developing firefox extension. on 1 <menupopup>, onpopupshowing calls javascript function. javascript function extracts list of names. these names have displayed in same popup.

how can this? need pass data (just use beans in java) browser javascript function. data can change every time popup called.

you need modify dom rapresenting menupopup. example:

<menulist>   <menupopup id="mymenupopup">     <menuitem id="firstitem" label="mozilla" value="http://mozilla.org"/>     <menuitem id="seconditem" label="slashdot" value="http://slashdot.org"/>     <menuitem id="thirditem" label="sourceforge" value="http://sf.net"/>   </menupopup> </menulist> 

now if want add item:

var mymenupopup = document.getelementbyid("mymenupopup"); var newitem = document.createelement("menuitem"); newitem.setattribute("id", "anotheritem"); mymenupopup.appendchild(newitem); 

if want remove item:

var itemtoremove = mymenupopup.getelementbyid("anotheritem"); mymenupopup.appendchild(itemtoremove); 

here can find more:

https://developer.mozilla.org/en/dynamically_modifying_xul-based_user_interface

edit:

i assume thet function returns array of names:

var namelists = yourfunction();  (var i=0; i<namelist.length; i++){   var newitem = document.createelement("menuitem");   newitem.setattribute("label", namelist[i]);   newitem.setattribute("id", "item" + i);   mymenupopup.appendchild(newitem); } 

i think better if call function make items before user click on menupopup, not on event invocation, because if have many items may takes little construct items list.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -