Chrome Extension - Dynamic Right-Click Menu
        Posted  
        
            by 
                user1277607
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user1277607
        
        
        
        Published on 2012-03-25T17:12:52Z
        Indexed on 
            2012/03/25
            17:29 UTC
        
        
        Read the original article
        Hit count: 255
        
JavaScript
|google-chrome-extension
I am trying to create an option in the right-click menu that is dynamic based on the user's action. If the user selects some text, then right-clicks, the option will say "Display It". If the user right-clicks without selecting some text, the option will say "Select Some Text First" and be grayed out. I am wondering how do I achieve this?
I currently have it so that the option will appear only when the user has selected some text. I am unsure how to modify it to meet my second requirements.
chrome.contextMenus.create ({
    title:"Display It!", contexts:["selection"], onclick:function(info,tab) {
        chrome.tabs.sendRequest(
            tab.id,
            {callFunction: "displaySidebar", info: info}, 
            function(response) {console.log(response);}
        );
    }           
});
© Stack Overflow or respective owner