views:

23

answers:

1

Hello, 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 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 !!

+4  A: 
  1. 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.

  2. Have a look at the menu element's appendItem method.

Felix Kling
@rockstarlive: Not so far. Restaring won't be required anymore if you use [JetPack](https://jetpack.mozillalabs.com/). To make restart easy, have a look at [Extension Developer](https://addons.mozilla.org/en-US/firefox/addon/7434/) and [other development extensions](https://developer.mozilla.org/en/Setting_up_extension_development_environment#Development_extensions).
Felix Kling