xul : creating a right click context menu item for only hyperlinks
I got a question to ask on building firefox plugin, basically my aim is to do following things,
1) In my plugin I want to show right click context menu item for only links[anchor tags
] and hide the menu 开发者_JAVA百科item for rest of the page
2) How to add dynamic list to my menu, i.e., adding the number of menu list items dynamically depending upon user's choice.
Can someOne point me to a right direction
Thanks !!
Bind an event listener for the
contextmenu
event and check whether the clicked element is a link, e.g.:window.addEventListener("contextmenu", function(e) { var menu = document.getElementById('your-menu-id'); if(e.target.nodeName == 'A') { menu.hidden = false; } else { menu.hidden = true; } }, false);
Read more about event properties and the
menu
element properties.Have a look at the
menu
element'sappendItem
method.
精彩评论