开发者

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


  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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜